crm最开始

crm最开始

见crm2项目

1.配置完成后-》逆向工程三张表,bean,mapper放进去

UserController

 @Controller
 @RequestMapping("user")
 public class UserController {
     @Autowired
     private IUserService userService;
     @PostMapping("login")
     public String login(String username, String password, HttpSession session){
         TUser user = userService.login(username,password);
         if (user!=null){
             user.setPassword(null);
             session.setAttribute("user",user);
             return "main";
        }else{
             session.setAttribute("msg","您输入的账号或密码有误,重新输入");
             return "redirect:/login.jsp";
        }
    }
     @GetMapping("rights")
     @ResponseBody
     public TUser rights(String name){
         return userService.getRightByUsername(name);
    }
 
 }

IUserService

 public interface IUserService {
     //根据用户账号密码登录
     TUser login(String username, String password);
     //根据用户名查询登录信息
     TUser getRightByUsername(String name);
 }

UserServiceImpl

 @Service
 public class UserServiceImpl implements IUserService {
     @Autowired
     private TUserMapper userMapper;
 
     @Override
     public TUser login(String username, String password) {
         TUserExample example = new TUserExample();
         example.createCriteria().andUsernameEqualTo(username).andPasswordEqualTo(password);
         List<TUser> tUsers = userMapper.selectByExample(example);
         if (tUsers!=null && tUsers.size()==1){
             return tUsers.get(0);
        }
         return null;
    }
 
     @Override
     public TUser getRightByUsername(String name) {
         //自定义sql
         return userMapper.selectRightByUsername(name);
    }
 }

TuserMapper中(新增自定义方法)

 //根据用户名查询user并加载user关联属性List<TSysRight>
 TUser selectRightByUsername(String name);

TUserMapper.xml中新增

 <resultMap id="userMap" type="tuser">
   <id column="id" property="id" jdbcType="INTEGER"/>
   <result column="roleName" property="rolename" jdbcType="VARCHAR"/>
   <collection property="rights" ofType="tsysright">
     <id column="right_id" property="rightId" jdbcType="INTEGER"/>
     <result column="right_pid" property="rightPid" jdbcType="INTEGER"/>
     <result column="right_type" property="rightType" jdbcType="VARCHAR"/>
     <result column="right_text" property="rightText" jdbcType="VARCHAR"/>
     <result column="right_url" property="rightUrl" jdbcType="VARCHAR"/>
     <result column="right_tip" property="rightTip" jdbcType="VARCHAR"/>
     <result column="right_parent_name" property="rightParentName" jdbcType="VARCHAR"/>
   </collection>
 </resultMap>
 <select id="selectRightByUsername" parameterType="string" resultMap="userMap">
  select t_user.id,t_user.roleName,t_sys_right.* from t_user left join
    t_role on t_user.role_id = t_role.role_id
    LEFT JOIN t_role_right
    on t_role.role_id = t_role_right.role_id
    LEFT JOIN t_sys_right
    on t_role_right.right_id = t_sys_right.right_id
    where t_user.userName = #{username}
 </select>

新增之后Tuser中添加关联属性

Tuser(并添加get set方法)

 //关联属性
 private List<TSysRight> rights;
 
 public List<TSysRight> getRights() {
         return rights;
    }
 
     public void setRights(List<TSysRight> rights) {
         this.rights = rights;
    }

初始配置完成

IndexController

 @Controller
 public class IndexController {
     @RequestMapping("{path}")
     public String index(@PathVariable String path){
         return path;
    }
 }

 

查询显示所有客户经理

UserController

 @PostMapping("customerManagerComboList")
 @ResponseBody
 public List<TUser> customerManagerComboList(){
     return userService.selectComBoList();
 }

IUserService

 public interface IUserService {
     //根据用户账号密码登录
     TUser login(String username, String password);
     //根据用户名查询登录信息
     TUser getRightByUsername(String name);
     //显示指派人
     List<TUser> selectComBoList();
 }

UserServiceImpl

 @Override
 public List<TUser> selectComBoList() {
     TUserExample example = new TUserExample();
     example.createCriteria().andRolenameEqualTo("客户经理");
     return userMapper.selectByExample(example);
 }

显示成功

posted @ 2022-06-26 20:35  为了她  阅读(38)  评论(0编辑  收藏  举报