| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package me.zhengjie.dao.jdbc.impl;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.core.RowCallbackHandler;
- import org.springframework.jdbc.core.RowMapper;
- import org.springframework.stereotype.Repository;
- import org.springframework.transaction.annotation.Transactional;
- import me.zhengjie.dao.jdbc.RoleDao;
- import me.zhengjie.application.bank.controller.vo.Role;
- @Repository
- @Transactional
- public class RoleDaoImpl implements RoleDao {
- @Autowired
- private JdbcTemplate jdbcTemplate;
- /**
- * 根据登录账户查询账户列表
- *
- * @param accountId
- * @param request
- * @return
- */
- @Override
- public List<Role> selectRoleByAccountId(Integer accountId, HttpServletRequest request) {
- String sql = "select * from `role` where `accountId`=" + accountId + " order by `sort` asc,`id` desc";
- return this.jdbcTemplate.query(sql, new RowMapper<Role>() {
- @Override
- public Role mapRow(ResultSet rs, int rowNum) throws SQLException {
- Role role = new Role();
- role.setId(rs.getInt("id"));
- role.setAccountId(rs.getInt("accountId"));
- role.setSort(rs.getInt("sort"));
- role.setTitle(rs.getString("title"));
- role.setMenuId(rs.getString("menuId"));
- role.setCreateTime(rs.getDate("createTime"));
- role.setUpdateTime(rs.getDate("updateTime"));
- return role;
- }
- });
- }
- /**
- * 查询角色详情
- *
- * @param id
- * @return
- */
- @Override
- public Role selectRoleDetailById(Integer id) {
- String sql = "select * from `role` where `id`=? order by id asc";
- Role role = new Role();
- Object[] arr = new Object[] { id };
- this.jdbcTemplate.query(sql, arr, new RowCallbackHandler() {
- @Override
- public void processRow(ResultSet rs) throws SQLException {
- role.setId(rs.getInt("id"));
- role.setTitle(rs.getString("title"));
- role.setMenuId(rs.getString("menuId"));
- }
- });
- return role;
- }
- /**
- * 修改角色信息
- *
- * @param role
- */
- @Override
- public void modifyRoleDetailById(Role role) {
- String menuId = "";
- if (role.getMenuId().equals("")) {
- menuId = null;
- } else {
- menuId = "0," + role.getMenuId() + ",0";
- }
- String sql = "update `role` set title=? , menuId=? where id=?";
- this.jdbcTemplate.update(sql, role.getTitle(), menuId, role.getId());
- }
- /**
- * 删除角色
- *
- * @param role
- */
- @Override
- public void deleteRoleDetailById(Role role) {
- String sql = "delete from `role` where id=?";
- this.jdbcTemplate.update(sql, role.getId());
- }
- /**
- * 创建角色
- *
- * @param role
- */
- @Override
- public void insertRoleDetailById(Role role) {
- String menuId = "";
- if (role.getMenuId().equals("")) {
- menuId = null;
- } else {
- menuId = "0," + role.getMenuId() + ",0";
- }
- String sql = "insert into `role` (accountId,title,menuId,createTime) VALUES (?,?,?,?)";
- this.jdbcTemplate.update(sql, role.getAccountId(), role.getTitle(), menuId, role.getCreateTime());
- }
- }
|