mybatis常用xml中sql语句查询通用条件查询模板

Posted weixin_ancenhw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis常用xml中sql语句查询通用条件查询模板相关的知识,希望对你有一定的参考价值。

<?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.demo.hw.mapper.TestMapper">
    <sql id="queryParam">
        <where>
            <if test="pageQuery.startDate !=null and pageQuery.startDate!=''">
                and start_date <![CDATA[>=]]> parseDateTimeBestEffort(#startDate)
            </if>
            <if test="pageQuery.endDate !=null and pageQuery.endDate!=''">
                and endDate <![CDATA[>=]]> parseDateTimeBestEffort(#endDate)
            </if>
            <if test="pageQuery.testId != null and pageQuery.testId != ''">
                and id = #pageQuery.testId
            </if>
        </where>
    </sql>
    <sql id="selectParam">
        id,start_date,endDate
    </sql>
    <select id="queryPlatformReport" resultType="com.pasig.bi.report.vo.resp.PlatformReportPageResp">
        select
        <include refid="selectParam"></include>
        from test
        <include refid="querySum"></include>
    </select>
</mapper>

以上是关于mybatis常用xml中sql语句查询通用条件查询模板的主要内容,如果未能解决你的问题,请参考以下文章

通用Mapper

Mybatis的SQL语句根据某些字段查不到值(语法不错)

MyBatis动态SQL

Mybatis动态SQL语句使用

MyBatis 动态 SQL 之通用 where

MyBatis增删改查