lxy-kit/tpl/MapperTpl.xml
2019-04-11 17:38:48 +08:00

141 lines
4.4 KiB
XML

#define buildIF(x)
<if test="#(x.field) != null#if((!x.isNumber)) and #(x.field) != ''#end">
#end
<?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="#(pkg).dao.#(bean)Mapper">
<!-- insert -->
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="#(pkg).domain.#(bean)">
insert into #(table)
(#for(x : fields)`#(x.field)`#if(!for.last),#end #end)
values
(#for(x : fields)#{#(x.field)}#if(!for.last),#end #end)
</insert>
<!-- findCount -->
<select id="findCount" parameterType="#(pkg).domain.#(bean)" resultType="Long">
select count(1) from #(table) where 1=1
<!-- 加入查询条件 -->
#if(condition && condition.length > 0)
<if test="condition != null and condition != ''">
and (
#for(x : condition)
#if(x)
#set(str=x)
#(str.substring(0, 1).toLowerCase() + str.substring(1)) like CONCAT('%',#{condition},'%') #if(!for.last)or #end
#end
#end
)
</if>
#end
#for(x : fields)
#if(x.filter == "1")
#@buildIF(x)
and `#(x.field)` = #{#(x.field)}
</if>
#elseif(x.filter == "like")
#@buildIF(x)
and `#(x.field)` like CONCAT('%',#{#(x.field)},'%')
</if>
#elseif(x.filter == "2")
<if test="extPara != null and extPara.start_#(x.field) != null">
and `datatime` &gt; #{start_#(x.field)}
</if>
<if test="extPara != null and extPara.end_#(x.field) != null">
and `datatime` &lt; #{start_#(x.field)}
</if>
#end
#end
#if(verify)
<if test="extPara != null and extPara.verify != null">
and id in (
select ids from (
select group_concat(id) ids,count(*) count from #(table) where `status` !=9 group by
#(verify)
) n where n.count > 1
)
</if>
#end
and `status` != 9
</select>
<!-- findList -->
<select id="findList" parameterType="java.util.Map" resultType="#(pkg).domain.#(bean)">
select
#for(x : fields)`#(x.field)`#if(!for.last),#end #end
from #(table) where 1=1
<!-- 加入查询条件 -->
#if(condition)
<if test="condition != null and condition != ''">
and (
#for(x : condition)
#if(x)
#(x.substring(0, 1).toLowerCase() + x.substring(1)) like CONCAT('%',#{condition},'%') #if(!for.last)or #end
#end
#end
)
</if>
#end
#for(x : fields)
#if(x.filter == "1")
#@buildIF(x)
and `#(x.field)` = #{#(x.field)}
</if>
#elseif(x.filter == "like")
#@buildIF(x)
and `#(x.field)` like CONCAT('%',#{#(x.field)},'%')
</if>
#elseif(x.filter == "2")
<if test="extPara != null and extPara.start_#(x.field) != null">
and `datatime` &gt; #{start_#(x.field)}
</if>
<if test="extPara != null and extPara.end_#(x.field) != null">
and `datatime` &lt; #{start_#(x.field)}
</if>
#end
#end
#if(verify)
<if test="extPara != null and extPara.verify != null">
and id in (
select ids from (
select group_concat(id) ids,count(*) count from #(table) where `status` !=9 group by
#(verify)
) n where n.count > 1
)
</if>
#end
and `status` != 9
<if test="maxResult != null and maxResult != ''">
#(order) limit #{startPosition},#{maxResult}
</if>
</select>
<!-- update -->
<update id="update" parameterType="#(pkg).domain.#(bean)">
update #(table)
set
id=id
#for(x : fields)
<if test="#(x.field) != null">
,`#(x.field)`=#{#(x.field)}
</if>
#end
where `id`=#{id}
</update>
<!-- deleteById 程序中只提供逻辑删除 -->
<delete id="deleteById" parameterType="Long">
update #(table) set status=9 where id=#{id}
</delete>
<!-- findById -->
<select id="findById" parameterType="Long" resultType="#(pkg).domain.#(bean)">
select #for(x : fields)#(x.field)#if(!for.last), #end #end
from #(table) where id=#{id}
</select>
</mapper>