其他分享
首页 > 其他分享> > mybatis 分页排序查询

mybatis 分页排序查询

作者:互联网

Map<String, Object> map = new HashMap<>();
Integer page = pagination.getPage();
Integer limit = pagination.getLimit();
map.put("start", (page - 1) * limit);
map.put("pageNo", limit);
map.put("field", pagination.getField());
map.put("order", pagination.getOrder());
<select id="querySentEmails" resultType="EmailDTO">
SELECT
m.*,
s.realUserName AS receiver,
FROM_UNIXTIME(m.createTime,'%Y-%m-%d') AS createTimeStr  秒级时间戳转换  -> FROM_UNIXTIME(a.createTime,'%Y-%m-%d %H:%i:%s') as createTimeStr
FROM
mail_info_data m
LEFT JOIN sys_users s ON m.receiverId = s.userId
<where>
    m.senderDelete != 1
    <if test="senderId !=null">
        AND m.senderId=#{senderId}
    </if>
    <if test="title != null and title !=''">
        AND m.title like concat('%',#{title},'%')  模糊查询 
    </if>
    <if test="receiver != null and receiver !=''">
        AND s.realUserName like concat('%',#{receiver},'%')
    </if>
    <if test="createTimeStartStr !=null and createTimeStartStr !=''">
        AND FROM_UNIXTIME(m.createTime,'%Y-%m-%d') &gt;= #{createTimeStartStr}  时间查询
    </if>
    <if test="createTimeEndStr !=null and createTimeEndStr !=''">
        AND FROM_UNIXTIME(m.createTime,'%Y-%m-%d') &lt;= #{createTimeEndStr}
    </if>
</where>
<choose>
    <when test="field !=null and  field  !=''"> 
        ORDER BY ${field} ${order}    分页
    </when>
    <otherwise>
        ORDER BY m.createTime desc   默认分页
    </otherwise>
</choose>
limit #{start}, #{pageNo}
</select>

 

标签:-%,map,pagination,分页,UNIXTIME,put,mybatis,排序,createTime
来源: https://www.cnblogs.com/luweiweicode/p/15232791.html