crud/main/java/com/dao/impl/RoleDaoImpl.java

41 lines
1.3 KiB
Java

package com.dao.impl;
import com.dao.RoleDao;
import com.domain.Role;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
public class RoleDaoImpl implements RoleDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<Role> findAll() {
List<Role> roleList = jdbcTemplate.query("select * from sys_role", new BeanPropertyRowMapper<Role>(Role.class));
return roleList;
}
public void save(Role role) {
jdbcTemplate.update("insert into sys_role values(?,?,?)",null,role.getRoleName(),role.getRoleDesc());
}
public List<Role> findRoleByUserId(Long id) {
List<Role> roles = jdbcTemplate.query("select * from sys_user_role ur,sys_role r where ur.roleId=r.id and ur.userId=?", new BeanPropertyRowMapper<Role>(Role.class), id);
return roles;
}
public void del(Long roleId) {
jdbcTemplate.update("delete from sys_user where id=?",roleId);
}
public void delUserRoleRel(Long roleId) {
jdbcTemplate.update("delete from sys_user_role where roleId=?",roleId);
}
}