CRM项目封装Query对象接收前端数据并在SQL中判空完成后完成用户信息修改------CRM项目

CRM项目封装Query对象接收前端数据并在SQL中判空完成后完成用户信息修改------CRM项目

java">package ***.alatus.web;

import ***.alatus.model.TUser;
import ***.alatus.query.UserQuery;
import ***.alatus.result.R;
import ***.alatus.service.UserService;
import ***.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Resource
    private UserService userService;
//    获取登录信息
    @GetMapping(value = "/api/login/info")
    public R loginInfo(Authentication authentication){
        TUser tUser = (TUser) authentication.getPrincipal();
        return R.OK(tUser);
    }
    //免登录验证
    //因为发送的请求过来首先会过filter那一关,能到这说明token验证都通过了,我们直接返回200即可
    @GetMapping(value = "/api/login/free")
    public R freeLogin(){
        return R.OK();
    }
//    查询用户列表
    @GetMapping(value = "/api/users")
//    传递参数current,可传可不传,
    public R userPage(@RequestParam(value = "current",required = false) Integer current){
        if(current == null){
            current = 1;
        }
//        返回结果为PageInfo
        PageInfo<TUser> userByPage = userService.getUserByPage(current);
        return R.OK(userByPage);
    }
    @GetMapping(value = "/api/user/{id}")
    public R userDetail(@PathVariable(value = "id")Integer id){
        TUser tUser = userService.getUserById(id);
        return R.OK(tUser);
    }
//    添加用户
    @PostMapping(value = "/api/user/add")
    public R addUser(UserQuery userQuery,@RequestHeader(value = "Authorization")String token){
        userQuery.setToken(token);
        int result = userService.saveUser(userQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }
//    编辑用户
    @PutMapping(value = "/api/user/edit")
    public R editUser(UserQuery userQuery,@RequestHeader(value = "Authorization")String token){
        userQuery.setToken(token);
        int result = userService.updateUser(userQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }
}
package ***.alatus.web;

import ***.alatus.model.TUser;
import ***.alatus.query.UserQuery;
import ***.alatus.result.R;
import ***.alatus.service.UserService;
import ***.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Resource
    private UserService userService;
//    获取登录信息
    @GetMapping(value = "/api/login/info")
    public R loginInfo(Authentication authentication){
        TUser tUser = (TUser) authentication.getPrincipal();
        return R.OK(tUser);
    }
    //免登录验证
    //因为发送的请求过来首先会过filter那一关,能到这说明token验证都通过了,我们直接返回200即可
    @GetMapping(value = "/api/login/free")
    public R freeLogin(){
        return R.OK();
    }
//    查询用户列表
    @GetMapping(value = "/api/users")
//    传递参数current,可传可不传,
    public R userPage(@RequestParam(value = "current",required = false) Integer current){
        if(current == null){
            current = 1;
        }
//        返回结果为PageInfo
        PageInfo<TUser> userByPage = userService.getUserByPage(current);
        return R.OK(userByPage);
    }
    @GetMapping(value = "/api/user/{id}")
    public R userDetail(@PathVariable(value = "id")Integer id){
        TUser tUser = userService.getUserById(id);
        return R.OK(tUser);
    }
//    添加用户
    @PostMapping(value = "/api/user/add")
    public R addUser(UserQuery userQuery,@RequestHeader(value = "Authorization")String token){
        userQuery.setToken(token);
        int result = userService.saveUser(userQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }
//    编辑用户
    @PutMapping(value = "/api/user/edit")
    public R editUser(UserQuery userQuery,@RequestHeader(value = "Authorization")String token){
        userQuery.setToken(token);
        int result = userService.updateUser(userQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }
}
package ***.alatus.service;

import ***.alatus.model.TUser;
import ***.alatus.query.UserQuery;
import ***.github.pagehelper.PageInfo;
import org.springframework.security.core.userdetails.UserDetailsService;

public interface UserService extends UserDetailsService {

    PageInfo<TUser> getUserByPage(Integer current);

    TUser getUserById(Integer id);

    int saveUser(UserQuery userQuery);

    int updateUser(UserQuery userQuery);
}
package ***.alatus.service;

import ***.alatus.model.TUser;
import ***.alatus.query.UserQuery;
import ***.github.pagehelper.PageInfo;
import org.springframework.security.core.userdetails.UserDetailsService;

public interface UserService extends UserDetailsService {

    PageInfo<TUser> getUserByPage(Integer current);

    TUser getUserById(Integer id);

    int saveUser(UserQuery userQuery);

    int updateUser(UserQuery userQuery);
}
package ***.alatus.service.impl;

import ***.alatus.constant.Constants;
import ***.alatus.mapper.TUserMapper;
import ***.alatus.model.TUser;
import ***.alatus.query.UserQuery;
import ***.alatus.util.JWTUtils;
import ***.github.pagehelper.PageHelper;
import ***.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;

@Service
public class UserServiceImpl implements ***.alatus.service.UserService {
    @Resource
    private TUserMapper tUserMapper;
//    注入一个密码加密器
    @Resource
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TUser tUser = tUserMapper.selectByLoginAct(username);
        if(tUser == null){
            throw new UsernameNotFoundException("登陆账号不存在");
        }
        return tUser;
    }

    @Override
    public PageInfo<TUser> getUserByPage(Integer current) {
//        设置PageHelper和分页情况
        PageHelper.startPage(current, Constants.PAGE_SIZE);
//        查询
        ArrayList<TUser> list = tUserMapper.selectUserByPage();
//        封装分页到PageInfo中
        PageInfo<TUser> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public TUser getUserById(Integer id) {
        return tUserMapper.selectDetailByPrimaryKey(id);
    }

    @Override
    public int saveUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
//        创建时间
        tUser.setCreateTime(new Date());
//        通过token解析出的用户获取ID作为创建者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setCreateBy(loginId);
        return tUserMapper.insertSelective(tUser);
    }

    @Override
    public int updateUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        if(StringUtils.hasText(userQuery.getLoginPwd())){
            tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
        }
//        编辑时间
        tUser.setEditTime(new Date());
//        通过token解析出的用户获取ID作为编辑者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setEditBy(loginId);
        return tUserMapper.updateByPrimaryKeySelective(tUser);
    }
}
package ***.alatus.service.impl;

import ***.alatus.constant.Constants;
import ***.alatus.mapper.TUserMapper;
import ***.alatus.model.TUser;
import ***.alatus.query.UserQuery;
import ***.alatus.util.JWTUtils;
import ***.github.pagehelper.PageHelper;
import ***.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;

@Service
public class UserServiceImpl implements ***.alatus.service.UserService {
    @Resource
    private TUserMapper tUserMapper;
//    注入一个密码加密器
    @Resource
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TUser tUser = tUserMapper.selectByLoginAct(username);
        if(tUser == null){
            throw new UsernameNotFoundException("登陆账号不存在");
        }
        return tUser;
    }

    @Override
    public PageInfo<TUser> getUserByPage(Integer current) {
//        设置PageHelper和分页情况
        PageHelper.startPage(current, Constants.PAGE_SIZE);
//        查询
        ArrayList<TUser> list = tUserMapper.selectUserByPage();
//        封装分页到PageInfo中
        PageInfo<TUser> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public TUser getUserById(Integer id) {
        return tUserMapper.selectDetailByPrimaryKey(id);
    }

    @Override
    public int saveUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
//        创建时间
        tUser.setCreateTime(new Date());
//        通过token解析出的用户获取ID作为创建者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setCreateBy(loginId);
        return tUserMapper.insertSelective(tUser);
    }

    @Override
    public int updateUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        if(StringUtils.hasText(userQuery.getLoginPwd())){
            tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
        }
//        编辑时间
        tUser.setEditTime(new Date());
//        通过token解析出的用户获取ID作为编辑者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setEditBy(loginId);
        return tUserMapper.updateByPrimaryKeySelective(tUser);
    }
}
package ***.alatus.mapper;

import ***.alatus.model.TUser;

import java.util.ArrayList;

public interface TUserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TUser record);

    int insertSelective(TUser record);

    TUser selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TUser record);

    int updateByPrimaryKey(TUser record);

    TUser selectByLoginAct(String username);

    ArrayList<TUser> selectUserByPage();

    TUser selectDetailByPrimaryKey(Integer id);
}
package ***.alatus.mapper;

import ***.alatus.model.TUser;

import java.util.ArrayList;

public interface TUserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TUser record);

    int insertSelective(TUser record);

    TUser selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TUser record);

    int updateByPrimaryKey(TUser record);

    TUser selectByLoginAct(String username);

    ArrayList<TUser> selectUserByPage();

    TUser selectDetailByPrimaryKey(Integer id);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="***.alatus.mapper.TUserMapper">
  <resultMap id="BaseResultMap" type="***.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="a***ount_no_expired" jdbcType="INTEGER" property="a***ountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="a***ount_no_locked" jdbcType="INTEGER" property="a***ountNoLocked" />
    <result column="a***ount_enabled" jdbcType="INTEGER" property="a***ountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
  </resultMap>
  <resultMap id="UserDetailResultMap" type="***.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="a***ount_no_expired" jdbcType="INTEGER" property="a***ountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="a***ount_no_locked" jdbcType="INTEGER" property="a***ountNoLocked" />
    <result column="a***ount_enabled" jdbcType="INTEGER" property="a***ountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
    <!--一对一关联-->
    <association property="createByPO" javaType="***.alatus.model.TUser">
      <id column="createById" jdbcType="INTEGER" property="id" />
      <result column="createByName" jdbcType="VARCHAR" property="name" />
    </association>
    <!--一对一关联-->
    <association property="editByPO" javaType="***.alatus.model.TUser">
      <id column="editById" jdbcType="INTEGER" property="id" />
      <result column="editName" jdbcType="VARCHAR" property="name" />
    </association>
  </resultMap>

  <sql id="Base_Column_List">
    id, login_act, login_pwd, `name`, phone, email, a***ount_no_expired, credentials_no_expired, 
    a***ount_no_locked, a***ount_enabled, create_time, create_by, edit_time, edit_by, last_login_time
  </sql>
  <select id="selectByLoginAct" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    where login_act = #{username,jdbcType=VARCHAR}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectDetailByPrimaryKey" parameterType="java.lang.Integer" resultMap="UserDetailResultMap">
    select
      tu.*,
      tu2.id createById, tu2.name createByName,
      tu3.id editById, tu3.name editName
    from t_user tu left join t_user tu2 on tu.create_by = tu2.id
                   left join t_user tu3 on tu.edit_by = tu3.id
    where tu.id = #{id, jdbcType=INTEGER}
  </select>
  <select id="selectUserByPage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user (login_act, login_pwd, `name`, 
      phone, email, a
***ount_no_expired,
      credentials_no_expired, a***ount_no_locked, 
      a***ount_enabled, create_time, create_by, 
      edit_time, edit_by, last_login_time
      )
    values (#{loginAct,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{a***ountNoExpired,jdbcType=INTEGER}, 
      #{credentialsNoExpired,jdbcType=INTEGER}, #{a***ountNoLocked,jdbcType=INTEGER}, 
      #{a***ountEnabled,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, 
      #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, #{lastLoginTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        login_act,
      </if>
      <if test="loginPwd != null">
        login_pwd,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="a***ountNoExpired != null">
        a***ount_no_expired,
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired,
      </if>
      <if test="a***ountNoLocked != null">
        a***ount_no_locked,
      </if>
      <if test="a***ountEnabled != null">
        a***ount_enabled,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="editBy != null">
        edit_by,
      </if>
      <if test="lastLoginTime != null">
        last_login_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null">
        #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="a***ountNoExpired != null">
        #{a***ountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="a***ountNoLocked != null">
        #{a***ountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="a***ountEnabled != null">
        #{a***ountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="***.alatus.model.TUser">
    update t_user
    <set>
      <if test="loginAct != null">
        login_act = #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null and loginPwd != ''">
        login_pwd = #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="a***ountNoExpired != null">
        a***ount_no_expired = #{a***ountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="a***ountNoLocked != null">
        a***ount_no_locked = #{a***ountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="a***ountEnabled != null">
        a***ount_enabled = #{a***ountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        edit_by = #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="***.alatus.model.TUser">
    update t_user
    set login_act = #{loginAct,jdbcType=VARCHAR},
      login_pwd = #{loginPwd,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      a***ount_no_expired = #{a***ountNoExpired,jdbcType=INTEGER},
      credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      a***ount_no_locked = #{a***ountNoLocked,jdbcType=INTEGER},
      a***ount_enabled = #{a***ountEnabled,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      edit_by = #{editBy,jdbcType=INTEGER},
      last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="***.alatus.mapper.TUserMapper">
  <resultMap id="BaseResultMap" type="***.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="a***ount_no_expired" jdbcType="INTEGER" property="a***ountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="a***ount_no_locked" jdbcType="INTEGER" property="a***ountNoLocked" />
    <result column="a***ount_enabled" jdbcType="INTEGER" property="a***ountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
  </resultMap>
  <resultMap id="UserDetailResultMap" type="***.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="a***ount_no_expired" jdbcType="INTEGER" property="a***ountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="a***ount_no_locked" jdbcType="INTEGER" property="a***ountNoLocked" />
    <result column="a***ount_enabled" jdbcType="INTEGER" property="a***ountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
    <!--一对一关联-->
    <association property="createByPO" javaType="***.alatus.model.TUser">
      <id column="createById" jdbcType="INTEGER" property="id" />
      <result column="createByName" jdbcType="VARCHAR" property="name" />
    </association>
    <!--一对一关联-->
    <association property="editByPO" javaType="***.alatus.model.TUser">
      <id column="editById" jdbcType="INTEGER" property="id" />
      <result column="editName" jdbcType="VARCHAR" property="name" />
    </association>
  </resultMap>

  <sql id="Base_Column_List">
    id, login_act, login_pwd, `name`, phone, email, a***ount_no_expired, credentials_no_expired, 
    a***ount_no_locked, a***ount_enabled, create_time, create_by, edit_time, edit_by, last_login_time
  </sql>
  <select id="selectByLoginAct" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    where login_act = #{username,jdbcType=VARCHAR}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectDetailByPrimaryKey" parameterType="java.lang.Integer" resultMap="UserDetailResultMap">
    select
      tu.*,
      tu2.id createById, tu2.name createByName,
      tu3.id editById, tu3.name editName
    from t_user tu left join t_user tu2 on tu.create_by = tu2.id
                   left join t_user tu3 on tu.edit_by = tu3.id
    where tu.id = #{id, jdbcType=INTEGER}
  </select>
  <select id="selectUserByPage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user (login_act, login_pwd, `name`, 
      phone, email, a
***ount_no_expired,
      credentials_no_expired, a***ount_no_locked, 
      a***ount_enabled, create_time, create_by, 
      edit_time, edit_by, last_login_time
      )
    values (#{loginAct,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{a***ountNoExpired,jdbcType=INTEGER}, 
      #{credentialsNoExpired,jdbcType=INTEGER}, #{a***ountNoLocked,jdbcType=INTEGER}, 
      #{a***ountEnabled,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, 
      #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, #{lastLoginTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        login_act,
      </if>
      <if test="loginPwd != null">
        login_pwd,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="a***ountNoExpired != null">
        a***ount_no_expired,
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired,
      </if>
      <if test="a***ountNoLocked != null">
        a***ount_no_locked,
      </if>
      <if test="a***ountEnabled != null">
        a***ount_enabled,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="editBy != null">
        edit_by,
      </if>
      <if test="lastLoginTime != null">
        last_login_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null">
        #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="a***ountNoExpired != null">
        #{a***ountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="a***ountNoLocked != null">
        #{a***ountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="a***ountEnabled != null">
        #{a***ountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="***.alatus.model.TUser">
    update t_user
    <set>
      <if test="loginAct != null">
        login_act = #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null and loginPwd != ''">
        login_pwd = #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="a***ountNoExpired != null">
        a***ount_no_expired = #{a***ountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="a***ountNoLocked != null">
        a***ount_no_locked = #{a***ountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="a***ountEnabled != null">
        a***ount_enabled = #{a***ountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        edit_by = #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="***.alatus.model.TUser">
    update t_user
    set login_act = #{loginAct,jdbcType=VARCHAR},
      login_pwd = #{loginPwd,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      a***ount_no_expired = #{a***ountNoExpired,jdbcType=INTEGER},
      credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      a***ount_no_locked = #{a***ountNoLocked,jdbcType=INTEGER},
      a***ount_enabled = #{a***ountEnabled,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      edit_by = #{editBy,jdbcType=INTEGER},
      last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
转载请说明出处内容投诉
CSS教程_站长资源网 » CRM项目封装Query对象接收前端数据并在SQL中判空完成后完成用户信息修改------CRM项目

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买