entity
package ${package}.po;
import java.io.Serializable;
import java.util.Date;
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
public class ${className} implements Serializable {
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
//$column.comments
private $column.attrType $column.attrname;
#end
#foreach ($column in $columns)
public void set${column.attrName}($column.attrType $column.attrname) {
this.$column.attrname = $column.attrname;
}
public $column.attrType get${column.attrName}() {
return $column.attrname;
}
#end
}
xml
<?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}.po.${className}" id="BaseResultMap">
<id column="${pk.columnName}" jdbcType="${pk.dataType}" property="${pk.attrname}" />
#foreach($column in $columns)
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
<result property="${column.attrname}" column="${column.columnName}" jdbcType="${column.dataType}"/>
#end
#end
</resultMap>
<sql id="Base_Column_List">
#foreach($column in $columns)
$column.columnName#if($velocityCount != $columns.size()), #end
#end
</sql>
<select id="selectByPrimaryKey" parameterType="${pk.attrType}"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ${tableName}
where ${pk.columnName} = #{${pk.attrname},jdbcType=${pk.dataType}}
</select>
<delete id="deleteByPrimaryKey" parameterType="${pk.attrType}">
delete from
${tableName}
where ${pk.columnName} = #{${pk.attrname},jdbcType=${pk.dataType}}
</delete>
<!-- Check Package -->
<insert id="insert" parameterType="${package}.po.${className}"#if($pk.extra == 'auto_increment')
useGeneratedKeys="true" keyProperty="${pk.columnName}" #end>
#if($pk.extra != 'auto_increment')
<selectKey keyProperty="${pk.columnName}" resultType="${pk.attrType}" order="AFTER">
select last_insert_id()
</selectKey>
#end
insert ${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,jdbcType=${column.dataType}}#if($velocityCount != $columns.size()), #end
#end
#end
)
</insert>
<!-- Check Package -->
<update id="updateByPrimaryKeySelective" parameterType="${package}.po.${className}">
update ${tableName}
<set>
#foreach($column in $columns)
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
<if test="${column.attrname} != null and ${column.attrname} != ''">
${column.columnName} = #{${column.attrname},jdbcType=${column.dataType}},
</if>
#end
#end
</set>
where id = #{${pk.attrname},jdbcType=${pk.dataType}}
</update>
<!-- Check Package -->
<update id="updateByPrimaryKey" parameterType="${package}.po.${className}">
update ${tableName}
set
#foreach($column in $columns)
${column.columnName} = #{${column.attrname},jdbcType=${column.dataType}}#if($velocityCount != $columns.size()),#end
#end
</update>
<sql id="condition">
#foreach($column in $columns)
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
<if test="${column.attrname} != null and ${column.attrname} != ''">
AND ${column.columnName} = #{${column.attrname},jdbcType=${column.dataType}}
</if>
#end
#end
</sql>
<sql id="table">
${tableName}
</sql>
<sql id="baseSelect">
SELECT
<include refid="Base_Column_List" />
FROM
<include refid="table" />
</sql>
<select id="findList" parameterType="map" resultMap="BaseResultMap">
<include refid="baseSelect" />
WHERE 1=1
<include refid="condition" />
</select>
<select id="findListByPage" parameterType="map" resultMap="BaseResultMap">
<include refid="baseSelect" />
WHERE 1=1
<include refid="condition" />
</select>
<select id="findTotal" parameterType="map" resultType="java.lang.Long">
SELECT COUNT(1) FROM (
<include refid="baseSelect" />
WHERE 1=1
<include refid="condition" />
) temp
</select>
<insert id="insertBatch" parameterType="java.util.List">
insert ${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 collection="list" item="item" index="index" separator=",">
(
#foreach($column in $columns)
#if($column.columnName != $pk.columnName || $pk.extra != 'auto_increment')
#{item.$column.attrname,jdbcType=${column.dataType}}#if($velocityCount != $columns.size()), #end
#end
#end
)
</foreach>
</insert>
</mapper>
dao
package ${package}.dao;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import ${package}.po.${className};
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
@Repository
public interface ${className}Dao{
${className} selectByPrimaryKey(${pk.attrType} id);
Integer deleteByPrimaryKey(${pk.attrType} id);
Integer insert(${className} entity);
Integer updateByPrimaryKeySelective(${className} entity);
Integer updateByPrimaryKey(${className} entity);
List<${className}> findList(Map<String,Object> params);
List<${className}> findListByPage(Map<String,Object> params);
Long findTotal(Map<String,Object> params);
Integer insertBatch(List<${className}> list);
}
service
package ${package}.service;
import java.util.List;
import java.util.Map;
import ${package}.po.${className};
/**
* ${comments}
* 业务接口
* @author ${author}
* @date ${datetime}
*/
public interface ${className}Service{
${className} selectByPrimaryKey(${pk.attrType} id);
Integer deleteByPrimaryKey(${pk.attrType} id);
Integer insert(${className} entity);
Integer updateByPrimaryKeySelective(${className} entity);
Integer updateByPrimaryKey(${className} entity);
List<${className}> findList(Map<String,Object> params);
List<${className}> findListByPage(Map<String,Object> params);
Long findTotal(Map<String,Object> params);
Integer insertBatch(List<${className}> list);
}
serviceImpl
package ${package}.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import ${package}.dao.${className}Dao;
import ${package}.po.${className};
import ${package}.service.${className}Service;
/**
* ${comments}
* 业务实现
* @author ${author}
* @date ${datetime}
*/
@Service
public class ${className}ServiceImpl implements ${className}Service{
@Autowired
private ${className}Dao ${classname}Dao;
@Override
public ${className} selectByPrimaryKey(${pk.attrType} id){
return ${classname}Dao.selectByPrimaryKey(id);
}
@Override
public Integer deleteByPrimaryKey(${pk.attrType} id){
return ${classname}Dao.deleteByPrimaryKey(id);
}
@Override
public Integer insert(${className} entity){
return ${classname}Dao.insert(entity);
}
@Override
public Integer updateByPrimaryKeySelective(${className} entity){
return ${classname}Dao.updateByPrimaryKeySelective(entity);
}
@Override
public Integer updateByPrimaryKey(${className} entity){
return ${classname}Dao.updateByPrimaryKey(entity);
}
@Override
public List<${className}> findList(Map<String,Object> params){
return ${classname}Dao.findList(params);
}
@Override
public List<${className}> findListByPage(Map<String,Object> params){
return ${classname}Dao.findListByPage(params);
}
@Override
public Long findTotal(Map<String,Object> params){
return ${classname}Dao.findTotal(params);
}
@Override
public Integer insertBatch(List<${className}> list){
return ${classname}Dao.insertBatch(list);
}
}
controller