我们在使用Mybatis时常常会遇到返回List集合中的参数类型无法满足我们的需求,这时候就要使用使用自定义的方式来定义属于自己的list集合。
type 写相关model的全路径。id是这个resultMap的唯一标识
<resultMap id="BaseResultMap" type="com.shiro.shirodemo.entity.OperatingRecord">
<id column="id" property="id" />
<result column="requestUrl" property="requestUrl" />
<result column="remoteAddr" property="remoteAddr" />
<result column="params" property="params" />
<result column="method" property="method" />
<result column="create_time" property="createTime" />
<result column="uid" property="uid"/>
<result column="flag" property="flag" />
</resultMap>
然后我们就可以使用了
<!-- select 区域 -->
<select id="findOperatingRecordByPage" resultMap="BaseResultMap">
SELECT
op_r.id,
op_r.remoteAddr,
op_r.params,
op_r.method,
op_r.create_time,
op_r.flag,
IFNULL(u.nickname, '未知') AS userName,
IFNULL(
sys_permission.`name`,
op_r.requestUrl
) AS permName
FROM
sys_operating_record AS op_r
LEFT JOIN sys_user AS u ON op_r.uid = u.id
LEFT JOIN sys_permission ON op_r.requestUrl = sys_permission.url
WHERE
(1 = 1)
<if test="''!=dto.keyword">
AND (op_r.requestUrl LIKE CONCAT('%',#{dto.keyword},'%')
OR op_r.remoteAddr LIKE CONCAT('%',#{dto.keyword},'%')
OR op_r.method LIKE CONCAT('%',#{dto.keyword},'%')
OR op_r.flag LIKE CONCAT('%',#{dto.keyword},'%')
OR u.nickname LIKE CONCAT('%',#{dto.keyword},'%'))
</if>
ORDER BY op_r.create_time DESC
</select>
</select>