contrlller.java.vm
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name}) 控制层
* @author $!author
* @since $!time.currTime()
*/
@RestController
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
@Autowired
private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
/**
* 查询 列表
* @param $!tool.firstLowerCase($tableInfo.name) 对象
* @return
*/
@PostMapping("/list")
public List<$!{tableInfo.name}> list(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)) {
List<$tableInfo.name> $!{tool.firstLowerCase($tableInfo.name)}List = $!{tool.firstLowerCase($tableInfo.name)}Service.list($!{tool.firstLowerCase($!{tableInfo.name})});
return $!{tool.firstLowerCase($tableInfo.name)}List;
}
/**
* 详情
* @param $!pk.name 主键
* @return
*/
@PostMapping("/detail")
public $!{tableInfo.name} detail(@RequestParam $!pk.shortType $!pk.name) {
return $!{tool.firstLowerCase($tableInfo.name)}Service.detail($!pk.name);
}
/**
* 添加
* @param $!tool.firstLowerCase($tableInfo.name) 对象
* @return
*/
@PostMapping("/save")
public $tableInfo.name save(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)){
$!{tool.firstLowerCase($tableInfo.name)}Service.save($!tool.firstLowerCase($tableInfo.name));
return $!tool.firstLowerCase($tableInfo.name);
}
/**
* 修改 根据主键更新数据
* @param $!tool.firstLowerCase($tableInfo.name) 对象
* @return
*/
@PutMapping("/edit")
public int edit(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)){
return $!{tool.firstLowerCase($tableInfo.name)}Service.edit($!tool.firstLowerCase($tableInfo.name));
}
/**
* 删除
* @param $!pk.name 主键
* @return
*/
@DeleteMapping("/delete")
public int delete(@RequestParam $!pk.shortType $!pk.name){
return $!{tool.firstLowerCase($tableInfo.name)}Service.delete($!pk.name);
}
/**
* 批量删除
* @param $!{pk.name}s 主键集合
* @return
*/
@DeleteMapping("/deleteByIds")
public int delete(@RequestBody List<$!pk.shortType> $!{pk.name}s){
int result = 0;
if ($!{pk.name}s!=null&&$!{pk.name}s.size()>0){
result = $!{tool.firstLowerCase($tableInfo.name)}Service.deleteByIds($!{pk.name}s);
}
return result;
}
}
service.java.vm
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name})服务接口层
* @author $!author
* @since $!time.currTime()
*/
public interface $!{tableName} {
/**
* 查询 列表
* @param $!tool.firstLowerCase($!{tableInfo.name}) 对象
* @return
*/
List<$!{tableInfo.name}> list($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 详情
* @param $!pk.name 主键
* @return
*/
$!{tableInfo.name} detail($!pk.shortType $!pk.name);
/**
* 添加
* @param $!tool.firstLowerCase($!{tableInfo.name}) 对象
* @return
*/
int save($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 修改 根据主键
* @param $!tool.firstLowerCase($!{tableInfo.name}) 对象
* @return
*/
int edit($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 删除
* @param $!pk.name 主键
* @return
*/
int delete($!pk.shortType $!pk.name);
/**
* 批量删除
* @param $!{pk.name}s 主键集合
* @return
*/
int deleteByIds(List<$!pk.shortType> ids);
}
serviceImpl.java.vm
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name})服务接口实现层
*
* @author $!author
* @since $!time.currTime()
*/
@Service
public class $!{tableName} implements $!{tableInfo.name}Service {
@Resource(type = $!{tableInfo.name}Dao.class)
private $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;
/**
* 查询列表
* @param $!tool.firstLowerCase($!{tableInfo.name}) 对象
* @return
*/
@Override
public List<$!{tableInfo.name}> list($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.findList($!tool.firstLowerCase($!{tableInfo.name}));
}
/**
* 详情
* @param $!pk.name 主键
* @return
*/
@Override
public $!{tableInfo.name} detail($!pk.shortType $!pk.name) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.findById($!{pk.name});
}
/**
* 添加
* @param $!tool.firstLowerCase($!{tableInfo.name}) 对象
* @return
*/
@Override
public int save($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insertSelective($!{tool.firstLowerCase($!{tableInfo.name})});
}
/**
* 修改
* @param $!tool.firstLowerCase($!{tableInfo.name}) 对象 根据主键修改
* @return
*/
@Override
public int edit($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.updateSelective($!{tool.firstLowerCase($!{tableInfo.name})});
}
/**
* 删除
* @param $!{pk.name} 主键
* @return
*/
@Override
public int delete($!pk.shortType $!pk.name) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name);
}
/**
* 批量删除
* @param $!{pk.name}s 主键集合
* @return
*/
@Override
public int deleteByIds(List<$!pk.shortType> ids) {
return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteByIds(ids);
}
}
dao.java.vm
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Dao"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name}表数据库访问层
*
* @author $!author
* @since $!time.currTime()
*/
@Mapper
public interface $!{tableName} {
/**
* 分页数据 查询 动态 属性不是null
* @param $!{tableInfo.name} 对象
* @return 实例对象的集合
*/
List<$!{tableInfo.name}> pageList($!pk.shortType $!pk.name);
/**
* 根据主键 查询单条数据
* @param $!pk.name 主键
* @return 实例对象
*/
$!{tableInfo.name} findById($!pk.shortType $!pk.name);
/**
* 动态 查询 多条数据 属性不是null
* @param $!{tableInfo.name} 对象
* @return 实例对象的集合
*/
List<$!{tableInfo.name}> findList($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 动态 查询 单条数据
* @param $!{tableInfo.name} 对象
* @return 实例对象
*/
$!{tableInfo.name} findOne($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 查询多条数据
* @param List<$!pk.shortType> 主键集合
* @return 实例对象的集合
*/
List<$!{tableInfo.name}> findListByIds(List<$!pk.shortType> list);
/**
* 动态 新增 属性不是null更新
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
int insertSelective($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 动态 批量 新增 属性不是null更新
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
int insertSelectiveBatch(List<$!{tableInfo.name}> list);
/**
* 动态 修改 属性不是null更新
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
int updateSelective($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 动态 批量 修改 属性不是null更新
* @param where 对象
* @param set对象
* @return int
*/
int updateSelectiveByField(@Param("where") $!{tableInfo.name} where, @Param("set") $!{tableInfo.name} set);
/**
* 动态 批量 修改 属性不是null更新
* @param List<$!{tableInfo.name})> 实例对象集合
* @return int
*/
int updateSelectiveBatchByIds(List<$!{tableInfo.name}> list);
/**
* 删除
* @param $!pk.name 主键
* @return int
*/
int deleteById($!pk.shortType $!pk.name);
/**
* 动态 删除 属性不是null更新
* @param $!{tableInfo.name} 实例对象
* @return int
*/
int deleteSelective($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 删除
* @param List<$!pk.shortType> 主键集合
* @return int
*/
int deleteByIds(List<$!pk.shortType> list);
/**
* 查询总数
* @return int
*/
int countAll();
/**
* 动态 查询 总数
* @param $!{tableInfo.name} 实例对象
* @return int
*/
int countSelective($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
}
mapper.xml.vm
##引入mybatis支持
$!{mybatisSupport.vm}
##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#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="$!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao">
<resultMap id="$!{tableInfo.name}ResultMap" type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" >
#foreach($column in $tableInfo.fullColumn)
<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
</resultMap>
<sql id="table_field">
#allSqlColumn()
</sql>
<!-- 分页查询 -->
<select id="pageList" resultMap="$!{tableInfo.name}Map">
select
<include refid="Base_Column_List" />
from $!tableInfo.obj.name
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
</if>
#end
</where>
limit #{(pageNum-1)*pageSize},#{pageNum*pageSize}
</select>
<!-- 根据主键 查询单条数据-->
<select id="findById" resultMap="$!{tableInfo.name}ResultMap" parameterType="$pk.type">
select
<include refid="table_field" />
from $!tableInfo.obj.name
where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}
</select>
<!--查询单条数据 根据对象属性不是null -->
<select id="findOne" resultMap="$!{tableInfo.name}ResultMap" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
select
<include refid="table_field" />
from $!tableInfo.obj.name
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
</if>
#end
</where>
</select>
<!-- 动态 查询 多条数据 属性不是null-->
<select id="findList" resultMap="$!{tableInfo.name}ResultMap" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
select
<include refid="table_field" />
from $!tableInfo.obj.name
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
</if>
#end
</where>
</select>
<!-- 查询多条数据 根据主键集合-->
<select id="findListByIds" resultMap="$!{tableInfo.name}ResultMap" parameterType="list">
select
<include refid="table_field" />
from $!tableInfo.obj.name
where $!pk.obj.name in
<foreach item="item" collection="list" separator="," open="(" close=")" index="index">
#{item}
</foreach>
</select>
<!--动态 添加 属性不是null-->
<insert id="insertSelective" keyProperty="$!pk.name" useGeneratedKeys="true" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
insert into $!{tableInfo.obj.name}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
$!column.obj.name,
</if>
#end
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
#{$!column.name,jdbcType=$!column.ext.jdbcType},
</if>
#end
</trim>
</insert>
<!--动态 批量 添加 属性不是null-->
<insert id="insertSelectiveBatch" keyProperty="$!pk.name" useGeneratedKeys="true" parameterType="list">
insert into $!{tableInfo.obj.name}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
$!column.obj.name,
</if>
#end
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<foreach item="item" collection="list" separator="," open="" close="" index="index">
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
#{$!column.name,jdbcType=$!column.ext.jdbcType},
</if>
#end
</foreach>
</trim>
</insert>
<!-- 动态 修改 根据主键 -->
<update id="updateSelective" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
update $!{tableInfo.obj.name}
<set>
#foreach($column in $tableInfo.otherColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
$!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType},
</if>
#end
</set>
where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}
</update>
<!-- 动态 修改 根据对象属性不是null -->
<update id="updateSelectiveByField">
update $!{tableInfo.obj.name}
<set>
#foreach($column in $tableInfo.otherColumn)
<if test="where.$!{column.name} == null and set.$!{column.name} != null#if($column.type.equals("java.lang.String")) and set.$!{column.name} != ''#end">
$!column.obj.name = #{set.$!{column.name},jdbcType=$!column.ext.jdbcType},
</if>
#end
</set>
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="where.$!{column.name} != null">
and $!column.obj.name = #{where.$!{column.name},jdbcType=$!column.ext.jdbcType}
</if>
#end
</where>
</update>
<!-- 动态 批量 修改 根据主键集合 属性不是null -->
<update id="updateSelectiveBatchByIds" parameterType="list">
update $!{tableInfo.obj.name}
<trim prefix="set" suffixOverrides=",">
#foreach($column in $tableInfo.otherColumn)
<trim prefix="$!{column.obj.name} = case" suffix="end,">
<foreach collection="list" item="item" index="index">
when $!pk.obj.name = #{item.$!pk.name} then #{item.$!column.name}
</foreach>
</trim>
#end
</trim>
where $!pk.obj.name in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.$!pk.name,jdbcType=$!pk.ext.jdbcType}
</foreach>
</update>
<!-- 删除 根据主键-->
<delete id="deleteById" parameterType="$pk.type">
delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name,jdbcType=$!pk.ext.jdbcType}
</delete>
<!--动态 删除 对象属性不是null-->
<delete id="deleteSelective" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}">
delete from $!{tableInfo.obj.name}
<where>
#foreach($column in $tableInfo.otherColumn)
<if test="$!column.name != null">
and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
</if>
#end
</where>
</delete>
<!--删除 根据主键集合-->
<delete id="deleteByIds" parameterType="list">
delete from $!{tableInfo.obj.name} where $!pk.obj.name in
<foreach item="item" collection="list" separator="," open="(" close=")" index="index">
#{item}
</foreach>
</delete>
<!-- 查询总数 -->
<select id="countAll" resultType="int">
select count(*) from $!{tableInfo.obj.name}
</select>
<!-- 动态 查询总数-->
<select id="countSelective" parameterType="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" resultType="int">
select count(*) from $!{tableInfo.obj.name}
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null">
and $!column.obj.name = #{$!column.name,jdbcType=$!column.ext.jdbcType}
</if>
#end
</where>
</select>
</mapper>
entity.java.vm
##定义初始变量
$!{define.vm}
##设置回调
#save("/entity", ".java")
##拿到主键
#setPackageSuffix("entity")
##导入
$!autoImport
import lombok.Data;
import lombok.ToString;
#foreach($column in $tableInfo.fullColumn)
#if($column.type.equals("java.time.LocalDateTime"))
import java.time.LocalDateTime;
#elseif($column.type.equals("java.util.Date"))
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
#end
#end
/**
* $!{tableInfo.comment}($!{tableInfo.name}) 实体类
*
* @author $!author
* @since $!time.currTime()
*/
@Data
@ToString
public class $!{tableInfo.name} {
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})/**
* ${column.comment}
*/#end
#if($column.type.equals("java.util.Date"))
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
#end
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}