vue-java-tutorials/spring-security/step-2/src/main/resources/mapper/UserMapper.xml

61 lines
2.3 KiB
XML

<?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="com.spring.step2.mapper.UserMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.spring.step2.domain.entity.UserEntity">
<id column="id" property="id"/>
<id column="username" property="username"/>
<id column="password" property="password"/>
<id column="email" property="email"/>
<id column="create_time" property="createTime"/>
<id column="update_time" property="updateTime"/>
<id column="create_user" property="createUser"/>
<id column="update_user" property="updateUser"/>
<id column="is_deleted" property="isDeleted"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id,username,password,email,create_time,update_time,create_user,update_user,is_deleted
</sql>
<!-- 分页查询用户内容 -->
<select id="selectListByPage" resultType="com.spring.step2.domain.vo.UserVo">
select
<include refid="Base_Column_List"/>
from t_user
<where>
is_deleted = 0
<if test="dto.username != null and dto.username != ''">
and username like CONCAT('%',#{dto.username},'%')
</if>
<if test="dto.email != null and dto.email != ''">
and email like CONCAT('%',#{dto.email},'%')
</if>
</where>
</select>
<!-- 根据用户id查找当前用户的权限 -->
<select id="selectPermissionByUserId" resultType="com.spring.step2.domain.entity.PermissionEntity">
SELECT DISTINCT p.*
FROM t_permission p
JOIN t_role_permission rp ON p.id = rp.permission_id
JOIN t_user_role ur ON rp.role_id = ur.role_id
WHERE ur.user_id = #{userId}
</select>
<!-- 根据用户名查询当前用户 -->
<select id="selectByUsername" resultType="com.spring.step2.domain.entity.UserEntity">
select
<include refid="Base_Column_List"/>
from t_user
<where>
<if test="username != null and username != ;;">
username=#{username}
</if>
</where>
</select>
</mapper>