Mybatis单输入框,多条件查询sql

119 阅读1分钟

<#if keyword?? && keyword != "">
and (g.contact_name like :keyword 
or g.contact_sex like :keyword 
or g.contact_email like :keyword 
or g.contact_mobile like :keyword 
or g.contact_qq like :keyword 
or g.contact_duties like :keyword 
or g.contact_address like :keyword) 
</#if>

mybatis中:

 

<where>

<if test="keyword!=null and keyword!= ''">

or d.accountId= #{keyword}

</if>

<if test="keyword!=null and keyword!= ''">

or d.name= #{keyword}

</if>

<if test="keyword!=null and keyword!= ''">

or d.IDNum= #{keyword}

</if>

</where>

 

或者三选一:

<where>

<choose>

<when test="accountid!=null and accountid!= ''">

and d.accountId= #{accountid}

</when>

<when test="name!=null and name!= ''">

and d.name= #{name}

</when>

<when test="idnum!=null and idnum!= ''">

and d.IDNum= #{idnum}

</when>