entity.java.vm
##导入宏定义
$! { define. vm}
##保存文件(宏定义)
#save ( "/entity/model" , ".java" )
##包路径(宏定义)
#setPackageSuffix ( "entity.model" )
##自动导入包(全局变量)
$! { autoImport. vm}
import com. example. easycode. entity. BaseModel ;
import io. swagger. annotations. ApiModelProperty ;
import com. baomidou. mybatisplus. annotation. TableName ;
import lombok. Data ;
##表注释(宏定义)
#tableComment ( "表实体类" )
@Data
@TableName ( "$!tableInfo.obj.name" )
public class $! { tableInfo. name} extends BaseModel {
#foreach ( $column in $tableInfo. fullColumn)
#if ( $! { column. name} != "createBy" and $! { column. name} != "createDate"
and $! { column. name} != "modifyBy" and $! { column. name} != "modifyDate"
and $! { column. name} != "dr" and $! { column. name} != "id" ) @ApiModelProperty ( "${column.comment}" )
private $! { tool. getClsNameByFullName ( $column. type) } $! { column. name} ;
#end
#end
#foreach ( $column in $tableInfo. pkColumn)
#break
#end
}
controller.java.vm
##导入宏定义
$! { define. vm}
##设置表后缀(宏定义)
#setTableSuffix ( "Controller" )
##保存文件(宏定义)
#save ( "/controller" , "Controller.java" )
##包路径(宏定义)
#setPackageSuffix ( "controller" )
##定义服务名
#set ( $serviceName = $! tool. append ( $! tool. firstLowerCase ( $! tableInfo. name) , "Service" ) )
##定义实体对象名
#set ( $entityName = $! tool. firstLowerCase ( $! tableInfo. name) )
import com. cbnb. system. model. util. AjaxResult ;
import $! { tableInfo. savePackageName} . entity. dto. $! { tableInfo. name} Dto ;
import $! { tableInfo. savePackageName} . entity. vo. $! { tableInfo. name} Vo ;
import $! { tableInfo. savePackageName} . entity. model. $! { tableInfo. name} ;
import $! { tableInfo. savePackageName} . service. $! { tableInfo. name} Service ;
import org. springframework. web. bind. annotation. * ;
import org. springframework. beans. factory. annotation. Autowired ;
import io. swagger. annotations. Api ;
import io. swagger. annotations. ApiOperation ;
import lombok. RequiredArgsConstructor ;
import com. cbnb. system. model. page. TableDataInfo ;
import java. io. Serializable ;
import java. util. List ;
##表注释(宏定义)
#tableComment ( "表控制层" )
@RestController
@RequestMapping ( "/$!tool.firstLowerCase($!tableInfo.name)" )
@RequiredArgsConstructor ( onConstructor_ = @Autowired )
@Api ( tags= "$!{tableInfo.name}控制器" )
public class $! { tableName} {
private final $! { tableInfo. name} Service $! { serviceName} ;
@PostMapping ( "/selectAll" )
@ApiOperation ( "分页查询所有数据" )
public AjaxResult < TableDataInfo < $! { tableInfo. name} Vo >> selectAll ( @RequestBody $! { tableInfo. name} Dto dto) {
return AjaxResult . success ( this . $! { serviceName} . selectAll ( dto) ) ;
}
@GetMapping ( "{id}" )
@ApiOperation ( "通过主键查询单条数据" )
public AjaxResult < $! { tableInfo. name} > selectOne ( @PathVariable Serializable id) {
return AjaxResult . success ( this . $! { serviceName} . getById ( id) ) ;
}
@PostMapping
@ApiOperation ( "新增数据" )
public AjaxResult < Boolean > insert ( @RequestBody $! { tableInfo. name} Dto dto) {
return AjaxResult . success ( this . $! { serviceName} . insert ( dto) ) ;
}
@PutMapping
@ApiOperation ( "修改数据" )
public AjaxResult < Boolean > edit ( @RequestBody $! { tableInfo. name} Dto dto) {
return AjaxResult . success ( this . $! { serviceName} . edit ( dto) ) ;
}
@DeleteMapping
@ApiOperation ( "删除数据" )
public AjaxResult < Boolean > delete ( @RequestParam ( "idList" ) List < Long > idList) {
return AjaxResult . success ( this . $! { serviceName} . removeByIds ( idList) ) ;
}
}
dto.java.vm
##导入宏定义
$! { define. vm}
##保存文件(宏定义)
#save ( "/entity/dto" , "Dto.java" )
##包路径(宏定义)
#setPackageSuffix ( "entity.dto" )
##自动导入包(全局变量)
$! { autoImport. vm}
import lombok. Data ;
import com. example. easycode. entity. BasePage ;
import io. swagger. annotations. ApiModelProperty ;
##表注释(宏定义)
#tableComment ( "接口接收参数将参数转化为数据库实体操作数据库使用" )
@Data
public class $! { tableInfo. name} Dto extends BasePage {
#foreach ( $column in $tableInfo. fullColumn)
#if ( ${ column. comment} ) @ApiModelProperty ( "${column.comment}" ) #end
private $! { tool. getClsNameByFullName ( $column. type) } $! { column. name} ;
#end
#foreach ( $column in $tableInfo. pkColumn)
#break
#end
}
mapper.java.vm
##导入宏定义
$! { define. vm}
##设置表后缀(宏定义)
#setTableSuffix ( "Mapper" )
##保存文件(宏定义)
#save ( "/mapper" , "Mapper.java" )
##包路径(宏定义)
#setPackageSuffix ( "mapper" )
import com. baomidou. mybatisplus. core. mapper. BaseMapper ;
import org. apache. ibatis. annotations. Param ;
import $! { tableInfo. savePackageName} . entity. model. $! tableInfo. name;
import $! { tableInfo. savePackageName} . entity. vo. $! { tableInfo. name} Vo ;
import $! { tableInfo. savePackageName} . entity. dto. $! { tableInfo. name} Dto ;
import java. util. List ;
##表注释(宏定义)
#tableComment ( "表数据库访问层" )
public interface $! { tableName} extends BaseMapper < $! tableInfo. name> {
List < $! { tableInfo. name} Vo > selectAll ( @Param ( "dto" ) $! { tableInfo. name} Dto dto) ;
}
mapperxml.java.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}.mapper.$!{tableInfo.name}Mapper" >
< select id= "selectAll" resultType= "$!{tableInfo.savePackageName}.entity.vo.$!{tableInfo.name}Vo" >
select * from $! tableInfo. obj. name
< / select>
< / mapper>
service.java.vm
##导入宏定义
$! { define. vm}
##设置表后缀(宏定义)
#setTableSuffix ( "Service" )
##保存文件(宏定义)
#save ( "/service" , "Service.java" )
##包路径(宏定义)
#setPackageSuffix ( "service" )
import com. baomidou. mybatisplus. extension. service. IService ;
import com. github. pagehelper. PageInfo ;
import $! { tableInfo. savePackageName} . entity. model. $! tableInfo. name;
import $! { tableInfo. savePackageName} . entity. dto. $! { tableInfo. name} Dto ;
import $! { tableInfo. savePackageName} . entity. vo. $! { tableInfo. name} Vo ;
##表注释(宏定义)
#tableComment ( "表服务接口" )
public interface $! { tableName} extends IService < $! tableInfo. name> {
PageInfo < $! { tableInfo. name} Vo > selectAll ( $! { tableInfo. name} Dto dto) ;
Boolean insert ( $! { tableInfo. name} Dto dto) ;
Boolean edit ( $! { tableInfo. name} Dto dto) ;
}
serviceImpl.java.vm
##导入宏定义
$! { define. vm}
##设置表后缀(宏定义)
#setTableSuffix ( "ServiceImpl" )
##保存文件(宏定义)
#save ( "/service/impl" , "ServiceImpl.java" )
##包路径(宏定义)
#setPackageSuffix ( "service.impl" )
import com. baomidou. mybatisplus. extension. service. impl. ServiceImpl ;
import $! { tableInfo. savePackageName} . mapper. $! { tableInfo. name} Mapper ;
import $! { tableInfo. savePackageName} . entity. model. $! { tableInfo. name} ;
import $! { tableInfo. savePackageName} . entity. dto. $! { tableInfo. name} Dto ;
import $! { tableInfo. savePackageName} . entity. vo. $! { tableInfo. name} Vo ;
import $! { tableInfo. savePackageName} . service. $! { tableInfo. name} Service ;
import org. springframework. stereotype. Service ;
import org. springframework. beans. BeanUtils ;
import com. github. pagehelper. PageHelper ;
import com. github. pagehelper. PageInfo ;
import org. springframework. util. Assert ;
import java. util. List ;
##表注释(宏定义)
#tableComment ( "表服务实现类" )
@Service
public class $! { tableName} extends ServiceImpl < $! { tableInfo. name} Mapper , $! { tableInfo. name} > implements $! { tableInfo. name} Service {
@Override
public PageInfo < $! { tableInfo. name} Vo > selectAll ( $! { tableInfo. name} Dto dto) {
PageHelper . startPage ( dto. getPageNum ( ) , dto. getPageSize ( ) ) ;
List < $! { tableInfo. name} Vo > list = baseMapper. selectAll ( dto) ;
PageInfo pageInfo = new PageInfo ( list) ;
return pageInfo;
}
@Override
public Boolean insert ( $! { tableInfo. name} Dto dto) {
$! { tableInfo. name} model = new $! { tableInfo. name} ( ) ;
BeanUtils . copyProperties ( dto, model) ;
return save ( model) ;
}
@Override
public Boolean edit ( $! { tableInfo. name} Dto dto) {
Assert . notNull ( dto. getId ( ) , "id is null!" ) ;
$! { tableInfo. name} model = new $! { tableInfo. name} ( ) ;
BeanUtils . copyProperties ( dto, model) ;
return updateById ( model) ;
}
}