代码如下:
[code="java"]
DataSource dataSource = SpringContextHolder.getBean("dataSource");
template = new JdbcTemplate(dataSource);
String sql = "INSERT INTO ca_role_authority(role_id,authority_id) VALUES ('"
+ roleId + "','" + authorityId + "')";
template.update(sql);
[/code]
测试代码:
[code="java"]
private void addRoleAuthorityRelation() {
DataService service = new DataService();
String roleId = "9527";
String authorityId = "999999";
service.addRoleAuthorityRelation(roleId, authorityId);
List auths = service.getAuthorityIdsByRoleId("9527");
System.out.println("auths size : " + auths.size());
for (String auth : auths) {
System.out.println(auth);
}
}
[/code]
打印出来的auths size 是0