欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MyBatis中的多条件查询语句

程序员文章站 2022-03-11 18:45:29
...

采用模糊查询的方式,主要是注意写法问题

<?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="fweb.commons.excel.import.template">
	
	<select id="getTemplateListByTypeIdAndName" resultType="com.hhwy.fweb.commons.excel.domain.ImportTemplate">
		SELECT
			fiet.id AS "id",
			fiet.template_key As "templateKey",
			fiet.more_Insert As "moreInsert",
			fiet.append_field AS "appendField",
			fiet.append_name AS "appendName",
			fiet.template_name AS "templateName",
			fiet.table_name AS "tableName"
			<!-- fiet.template_type_id As "templateTypeId" -->
		FROM
			fweb_import_exc_template AS fiet
		 <trim prefix="WHERE ("  suffix=")" prefixOverrides="AND |OR ">
		 <!-- <if test="templateName!=null and templateName!=''">
			 fiet.template_name LIKE CONCAT(CONCAT('%','${templateName}'),'%')
		 </if> 
		 <if test="id!=null and id!=''">
			 fiet.id=#{id}
		</if> -->
		<if test="templateName!=null and id!=null" >
		 fiet.template_name Like CONCAT(CONCAT('%','${templateName}'),'%') Or fiet.id Like CONCAT(CONCAT('%','${id}'),'%')
		</if>
		<if test="template_type_id!=null and template_type_id!=''">
			 fiet.template_type_id=#{template_type_id}
		</if>
		</trim>
		<!-- WHERE
		    -->
		ORDER BY create_time DESC
	</select>
	
</mapper>