mybatis框架中使用like模糊查询
mapper api接口中
List<Map> getUnderRegionList(@Param("regicode")String regicode);
mapper api接口所对应的xml
<select id="getUnderRegionList" parameterType="java.util.Map" resultType="java.util.Map">select IN_CODE id, P_IN_CODE pid, DISP_NAME realname, concat('[', IN_CODE, ']', DISP_NAME) namefrom xt_region where IN_CODE like CONCAT('%',#{regicode},'%') </select>
动态sql
mapper api接口中
List<Map> getXtUserInfoByUseStatus(@Param("usestatus")String usestatus,@Param("name")String name,@Param("code")String code);
mapper api接口所对应的xml
<select id="getXtUserInfoByUseStatus" parameterType="java.util.Map" resultType="java.util.Map">select u.ID id, u.NAME name,u.CODE code,u.PHONENO phoneno,u.ENTENAME entename, u.entetype, u.REGICODE regicode, r.DISP_NAME reginame, u.usestatus from xt_user uleft join xt_region r on r.DISP_CODE = u.REGICODEwhere u.usestatus = #{usestatus}<if test="name != ''">and u.NAME = #{name}</if><if test="code != ''">and u.CODE = #{code}</if>order by u.ID </select>