自定义mapper例子

mapper.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="ml.yompc.spring.security.oauth2.server.mapper.TbPermissionMapper">
  <resultMap id="BaseResultMap" type="ml.yompc.spring.security.oauth2.server.domain.TbPermission">
    <!--@mbg.generated generated on Wed Aug 21 22:39:20 CST 2019.-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="enname" jdbcType="VARCHAR" property="enname" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="description" jdbcType="VARCHAR" property="description" />
    <result column="created" jdbcType="TIMESTAMP" property="created" />
    <result column="updated" jdbcType="TIMESTAMP" property="updated" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated generated on Wed Aug 21 22:39:20 CST 2019.-->
    id, parent_id, `name`, enname, url, description, created, updated
  </sql>
  <select id="selectByUserId" resultMap="BaseResultMap">
    SELECT
	tp.*
FROM
	tb_user AS u
	LEFT JOIN tb_user_role AS ur ON u.id = ur.user_id
	LEFT JOIN tb_role_permission AS rp ON ur.role_id = rp.role_id
	LEFT JOIN tb_role AS tr ON tr.id = u.id
	LEFT JOIN tb_permission AS tp ON tp.id = rp.permission_id
WHERE
	u.id = #{id}
  </select>
</mapper>

mapper/mapper接口

package ml.yompc.spring.security.oauth2.server.mapper;

import ml.yompc.spring.security.oauth2.server.domain.TbPermission;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.MyMapper;

import java.util.List;

/**
 * @email yom535@outlook.com
 * @author: 有民(yom535)
 * @date: 2019/8/21
 * @time: 22:39
 */
public interface TbPermissionMapper extends MyMapper<TbPermission> {
    List<TbPermission> selectByUserId(@Param("id") Long id);
}