controller.java.vm
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##定义固定路径变量
#set($baseProjectImportPath = $tool.append("com.xxx.common.core",".web"))
##设置回调
$!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 $!{baseProjectImportPath}.controller.BaseController;
import $!{baseProjectImportPath}.domain.AjaxResult;
import $!{baseProjectImportPath}.page.TableDataInfo;
import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
@Api(value = "$!{tableInfo.comment}", tags = {"$!{tableInfo.comment}"})
public class $!{tableName} extends BaseController {
@Autowired
private I$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
@ApiOperation(value = "查询$!{tableInfo.comment}列表")
@GetMapping("/list")
public TableDataInfo list($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name))
{
startPage();
List<$!{tableInfo.name}> list = $!{tool.firstLowerCase($tableInfo.name)}Service.select$!{tableInfo.name}List($!tool.firstLowerCase($tableInfo.name));
return getDataTable(list);
}
@ApiOperation(value = "单个查询$!{tableInfo.comment}")
@GetMapping("/one/{id}")
public AjaxResult oneById( @PathVariable("id") $!pk.shortType id){
return AjaxResult.success($!tool.firstLowerCase($tableInfo.name)Service. select$!{tableInfo.name}OneById(id));
}
@ApiOperation(value = "count$!{tableInfo.comment}列表")
@GetMapping("/count")
public AjaxResult count($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)){
return AjaxResult.success($!tool.firstLowerCase($tableInfo.name)Service. select$!{tableInfo.name}Count( $!tool.firstLowerCase($tableInfo.name)));
}
@ApiOperation(value = "单个条件查询$!{tableInfo.comment}对象")
@GetMapping("/detail/one")
public AjaxResult detailOne($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)){
return AjaxResult.success($!tool.firstLowerCase($tableInfo.name)Service. select$!{tableInfo.name}One( $!tool.firstLowerCase($tableInfo.name)));
}
@ApiOperation(value = "新增$!{tableInfo.comment}")
@PostMapping
public AjaxResult add(@RequestBody $!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)){
return toAjax($!tool.firstLowerCase($tableInfo.name)Service. insert$!{tableInfo.name}($!tool.firstLowerCase($tableInfo.name)));
}
@ApiOperation(value = "修改$!{tableInfo.comment}")
@PutMapping
public AjaxResult edit(@RequestBody $!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)){
return toAjax($!tool.firstLowerCase($tableInfo.name)Service. update$!{tableInfo.name}($!tool.firstLowerCase($tableInfo.name)));
}
@ApiOperation(value = "单个删除$!{tableInfo.comment}")
@DeleteMapping("/remove/one/{$!pk.name}")
public AjaxResult removeOneById( @PathVariable("$!pk.name") $!pk.shortType $!pk.name){
return AjaxResult.success($!tool.firstLowerCase($tableInfo.name)Service. delete$!{tableInfo.name}OneById($!pk.name));
}
@ApiOperation(value = "批量删除$!{tableInfo.comment}")
@DeleteMapping("/remove/batch/{$tool.append($!pk.name,'s')}")
public AjaxResult batchRemove( @PathVariable("$tool.append($!pk.name,'s')") $!pk.shortType$tool.append('[',']') $tool.append($!pk.name,'s')){
return AjaxResult.success($!tool.firstLowerCase($tableInfo.name)Service. batchRemove$!{tableInfo.name}($tool.append($!pk.name,'s')));
}
}
domain.java.vm
##引入宏定义
$!{define.vm}
##使用宏定义设置回调(保存位置与文件后缀)
#save("/domain", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("domain")
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
##使用全局变量实现默认包导入
$!{autoImport.vm}
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@ApiModel(value = "$!{tableInfo.comment}-实体类", description = "$!{tableInfo.comment}-实体类")
public class $!{tableInfo.name} implements Serializable {
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})#end
@ApiModelProperty(value = "$!{column.comment}", name = "$!{column.name}")
#if(${column.type}=="java.util.Date")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#if(${column.type}!="java.util.Date")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#end
}
mapper.java.vm
##导入宏定义
$!{define.vm}
##设置表后缀(宏定义)
#setTableSuffix("Mapper")
##保存文件(宏定义)
#save("/mapper", "Mapper.java")
##包路径(宏定义)
#setPackageSuffix("mapper")
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
import $!{tableInfo.savePackageName}.domain.$!tableInfo.name;
import java.util.List;
import org.apache.ibatis.annotations.Param;
##表注释(宏定义)
#tableComment("表数据库访问层")
public interface $!{tableName} {
List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
$!{tableInfo.name} select$!{tableInfo.name}OneById($!pk.shortType $!pk.name);
$!{tableInfo.name} select$!{tableInfo.name}One($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
int insert$!{tableInfo.name} ($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
int update$!{tableInfo.name} ($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
Long select$!{tableInfo.name}Count($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
int delete$!{tableInfo.name}ById($!pk.shortType $!pk.name);
int batchRemove$!{tableInfo.name}( $!pk.shortType$tool.append('[',']') $tool.append($!pk.name,'s'));
int batchInsert(@Param("entities") List<$!{tableInfo.name}> entities);
}
service.java.vm
##导入宏定义
$!{define.vm}
##设置表后缀(宏定义)
#setTableSuffix("Service")
##保存文件(宏定义)
#saveI("/service", "Service.java")
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
##包路径(宏定义)
#setPackageSuffix("service")
import java.util.List;
import $!{tableInfo.savePackageName}.domain.$!tableInfo.name;
##表注释(宏定义)
#tableComment("表服务接口")
public interface I$!{tableName} {
List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
$!{tableInfo.name} select$!{tableInfo.name}OneById($!pk.shortType $!pk.name);
$!{tableInfo.name} select$!{tableInfo.name}One($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
int insert$!{tableInfo.name} ($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
int update$!{tableInfo.name} ($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
Long select$!{tableInfo.name}Count($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name));
int delete$!{tableInfo.name}OneById($!pk.shortType $!pk.name);
int batchRemove$!{tableInfo.name}( $!pk.shortType$tool.append('[',']') $tool.append($!pk.name,'s'));
}
serviceImpl.java.vm
##导入宏定义
$!{define.vm}
##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")
##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java")
##包路径(宏定义)
#setPackageSuffix("service.impl")
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
##表注释(宏定义)
#tableComment("表服务实现类")
@Service
public class $!{tableName} implements I$!{tableInfo.name}Service {
@Autowired
private $!{tableInfo.name}Mapper $!tool.firstLowerCase($tableInfo.name)Mapper;
@Override
public List<$!{tableInfo.name}> select$!{tableInfo.name}List($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. select$!{tableInfo.name}List($!tool.firstLowerCase($tableInfo.name));
}
@Override
public $!{tableInfo.name} select$!{tableInfo.name}OneById($!pk.shortType $!pk.name) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. select$!{tableInfo.name}OneById( $!pk.name);
}
@Override
public $!{tableInfo.name} select$!{tableInfo.name}One($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. select$!{tableInfo.name}One( $!tool.firstLowerCase($tableInfo.name));
}
@Override
public int insert$!{tableInfo.name}($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. insert$!{tableInfo.name}($!tool.firstLowerCase($tableInfo.name));
}
@Override
public int update$!{tableInfo.name}($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. update$!{tableInfo.name}($!tool.firstLowerCase($tableInfo.name));
}
@Override
public Long select$!{tableInfo.name}Count($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. select$!{tableInfo.name}Count($!tool.firstLowerCase($tableInfo.name));
}
@Override
public int delete$!{tableInfo.name}OneById($!pk.shortType $!pk.name) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. delete$!{tableInfo.name}ById( $!pk.name);
}
@Override
public int batchRemove$!{tableInfo.name}( $!pk.shortType$tool.append('[',']') $tool.append($!pk.name,'s')) {
return $!tool.firstLowerCase($tableInfo.name)Mapper. batchRemove$!{tableInfo.name}( $tool.append($!pk.name,'s'));
}
}
mapper.xml.vm
##引入mybatis支持
$!{mybatisSupport.vm}
##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper/$tool.firstLowerCase($!{tableInfo.name})"))
##拿到主键
#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}.mapper.$!{tableInfo.name}Mapper">
<resultMap type="$!{tableInfo.savePackageName}.domain.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
</resultMap>
<select id="select$!{tableInfo.name}List" resultMap="$!{tableInfo.name}Map">
select #allSqlColumn() from $!{tableInfo.obj.getName()}
<where>
#foreach($column in $tableInfo.fullColumn)
#if($column.comment.endsWith("LIKE"))
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">and $!column.obj.name like concat('%', #{$!column.name}, '%') </if>
#else
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">and $!column.obj.name = #{$!column.name} </if>
#end
#end
</where>
</select>
<insert id="insert$!{tableInfo.name}" >
insert into $!{tableInfo.obj.name}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $tableInfo.fullColumn)
<if test="$!{column.name} != null">$!column.obj.name,</if>
#end
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $tableInfo.fullColumn)
<if test="$!{column.name} != null">#{$!{column.name}},</if>
#end
</trim>
</insert>
<update id="update$!{tableInfo.name}" >
update $!{tableInfo.obj.name}
<trim prefix="SET" suffixOverrides=",">
#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},</if>
#end
</trim>
where $!pk.obj.name = #{$!pk.name}
</update>
<select id="select$!{tableInfo.name}OneById" resultMap="$!{tableInfo.name}Map">
select #allSqlColumn()
from $!tableInfo.obj.name
where $!pk.obj.name = #{$!pk.name}
</select>
<select id="select$!{tableInfo.name}Count" resultType="java.lang.Long">
select count(1) from $!tableInfo.obj.name
<where>
#foreach($column in $tableInfo.fullColumn)
#if($column.comment.endsWith("LIKE"))
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">and $!column.obj.name like concat('%', #{$!column.name}, '%') </if>
#else
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">and $!column.obj.name = #{$!column.name} </if>
#end
#end
</where>
</select>
<select id="select$!{tableInfo.name}One" resultMap="$!{tableInfo.name}Map">
select #allSqlColumn() 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} </if>
#end
</where>
</select>
<delete id="delete$!{tableInfo.name}ById" > delete from $!tableInfo.obj.name where $!pk.obj.name = #{$!pk.name} </delete>
<delete id="batchRemove$!{tableInfo.name}">
delete from $!{tableInfo.obj.name} where $!pk.obj.name in
<foreach item="$!pk.name" collection="array" open="(" separator="," close=")">
#{$!pk.name}
</foreach>
</delete>
<insert id="batchInsert" >
insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values
<foreach collection="entities" item="entity" separator=",">
(#foreach($column in $tableInfo.fullColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
</foreach>
</insert>
</mapper>