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>

 

上一篇:使用moment.js把国际化时间转标准时间


下一篇:今日校园 请假相关接口(天津理工大学版)