You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.1 KiB
103 lines
3.1 KiB
<?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="${package}.dao.${className}Dao">
|
|
|
|
<!-- 可根据自己的需求,是否要使用 -->
|
|
<resultMap type="${package}.entity.${className}Entity" id="${classname}Map">
|
|
#foreach($column in $columns)
|
|
<result property="${column.attrname}" column="${column.columnName}"/>
|
|
#end
|
|
</resultMap>
|
|
|
|
<select id="queryObject" resultType="${package}.entity.${className}Entity">
|
|
select * from ${tableName} where ${pk.columnName} = #{value}
|
|
</select>
|
|
|
|
<select id="queryList" resultType="${package}.entity.${className}Entity">
|
|
select * from ${tableName} where 1=1
|
|
<if test="${columns[1].attrname} != null and ${columns[1].attrname} != ''">
|
|
and ${columns[1].attrname} like '%${${columns[1].attrname}}%'
|
|
</if>
|
|
|
|
#foreach($column in $columns)
|
|
#if($column.columnName == 'user')
|
|
<if test="user != null and user != ''">
|
|
and user = #{user}
|
|
</if>
|
|
#end
|
|
#end
|
|
|
|
|
|
<choose>
|
|
<when test="sidx != null and sidx.trim() != ''">
|
|
order by ${sidx} ${order}
|
|
</when>
|
|
<otherwise>
|
|
order by ${pk.columnName} desc
|
|
</otherwise>
|
|
</choose>
|
|
<if test="offset != null and limit != null">
|
|
limit #{offset}, #{limit}
|
|
</if>
|
|
</select>
|
|
|
|
<select id="queryTotal" resultType="int">
|
|
select count(*) from ${tableName} where 1=1
|
|
<if test="${columns[1].attrname} != null and ${columns[1].attrname} != ''">
|
|
and ${columns[1].attrname} like '%${${columns[1].attrname}}%'
|
|
</if>
|
|
#foreach($column in $columns)
|
|
#if($column.columnName == 'user')
|
|
<if test="user != null and user != ''">
|
|
and user = #{user}
|
|
</if>
|
|
#end
|
|
#end
|
|
</select>
|
|
|
|
<insert id="save" parameterType="${package}.entity.${className}Entity"#if($pk.extra == 'auto_increment') useGeneratedKeys="true" keyProperty="$pk.attrname"#end>
|
|
insert into ${tableName}
|
|
(
|
|
#foreach($column in $columns)
|
|
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
|
|
`$column.columnName`#if($velocityCount != $columns.size()), #end
|
|
|
|
#end
|
|
#end
|
|
)
|
|
values
|
|
(
|
|
#foreach($column in $columns)
|
|
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
|
|
#{$column.attrname}#if($velocityCount != $columns.size()), #end
|
|
|
|
#end
|
|
#end
|
|
)
|
|
</insert>
|
|
|
|
<update id="update" parameterType="${package}.entity.${className}Entity">
|
|
update ${tableName}
|
|
<set>
|
|
#foreach($column in $columns)
|
|
#if($column.columnName != $pk.columnName)
|
|
<if test="$column.attrname != null">`$column.columnName` = #{$column.attrname}#if($velocityCount != $columns.size()), #end</if>
|
|
#end
|
|
#end
|
|
</set>
|
|
where ${pk.columnName} = #{${pk.attrname}}
|
|
</update>
|
|
|
|
<delete id="delete">
|
|
delete from ${tableName} where ${pk.columnName} = #{value}
|
|
</delete>
|
|
|
|
<delete id="deleteBatch">
|
|
delete from ${tableName} where ${pk.columnName} in
|
|
<foreach item="${pk.attrname}" collection="array" open="(" separator="," close=")">
|
|
#{${pk.attrname}}
|
|
</foreach>
|
|
</delete>
|
|
|
|
</mapper> |