mybatis采用sql查询语句案列多参数
Posted weixin_ancenhw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis采用sql查询语句案列多参数相关的知识,希望对你有一定的参考价值。
//可直接定义数组为字符串类型
private string citys
/**
* 定义查询的参数
* @param page
* @param PageQuery
* @return
*/
Page<CustomerModel> getPageCustomerModel(Page page, @Param("pageQuery") PageQuery PageQuery);
<if test="pageQuery.citys != null and pageQuery.citys != ''">
<bind name="cts" value="pageQuery.citys.split(';')"/>
and city in
<foreach collection="cts" open="(" close=")" item="ct" separator=",">
#ct
</foreach>
</if>
//多条件查询
<if test="pageQuery.citys!= null and pageQuery.citys!= ''">
<choose>
<when test="pageQuery.citys.indexOf('ancen') >= 0">
and citys in
<bind name="citys" value="pageQuery.citys.split(',')"/>
<foreach collection="citys" open="(" close=")" item="city" separator=",">
#city
</foreach>
</when>
<otherwise>
and citys in
<bind name="citys" value="pageQuery.citys .split(',')"/>
<foreach collection="citys" open="(" close=")" item="city" separator=",">
CAST((#city), 'Int256')
</foreach>
</otherwise>
</choose>
</if>
//多条件参数
<select id="getPageBranchReport" resultType="com.pasig.bi.report.vo.resp.BranchReportPageResp">
select a.id,a.name,b.value from a
left join b
on a.id=b.id
<include refid="commonSql">
<property name="num" value="11"/>
<property name="tablename" value="t_stu1"/>
<property name="columnname" value="col1"/>
</include>
<include refid="commonSql">
<property name="num" value="12"/>
<property name="tablename" value="t_stu2"/>
<property name="columnname" value="col2"/>
</include>
<sql id="branchCommonSql">
LEFT JOIN
(select
col1 as $columnname
where num=$num
from $tablename)
</sql>
以上是关于mybatis采用sql查询语句案列多参数的主要内容,如果未能解决你的问题,请参考以下文章
MyBatis应用开发映射之参数绑定parameterType
mybatis sql in 查询(mybatis sql语句传入参数是list)mybatis中使用in查询时in怎么接收值