目的
给我一张表,只需要两分钟就能生成接口。开发效率大幅度提高有木有。
资料
easy code官方介绍
参考教程
配置记录
该配置是适应了公司项目结构后的版本,需要使用的话,可以把controller层打印日志的部分去掉。
entity
该文件引用的宏定义
注意
- id使用varchar类型
- 数据库建表要写上表注释和字段注释
- 如果创建时间字段不是使用的create_time,请加上
@CreatedDate
注解 - 如果更新时间字段不是使用的update_time,请加上
@LastModifiedDate
注解
##引入宏定义
$!define
##使用宏定义设置回调(保存位置与文件后缀)
#save("/repository/entity", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("repository.entity")
##使用全局变量实现默认包导入
$!autoImport
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.io.Serializable;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
@Entity
@Table(name = "$!{tableInfo.obj.name}")
##@org.hibernate.annotations.Table(appliesTo = "$!{tableInfo.obj.name}",comment = "$!{tableInfo.comment}")
@JsonIgnoreProperties(ignoreUnknown = true)
@EntityListeners(AuditingEntityListener.class)
public class $!{tableInfo.name} implements Serializable {
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.pkColumn)
@Id
@Column(name ="$!{column.obj.name}",length=255)
@GenericGenerator(name="systemUUID",strategy="uuid")
@GeneratedValue(generator="systemUUID")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.otherColumn)
#if(${column.comment})
/**
* ${column.comment}
*/
#end
#if($!{column.obj.name} == "create_time")
@CreatedDate
#elseif($!{column.obj.name} == "update_time")
@LastModifiedDate
#end
@Column(name = "$!{column.obj.name}")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
dao
从dao后面的模板都是使用的自定义定义。主要是为了用下模板语法。
##定义初始变量
#set($className = $tool.append($tableInfo.name, "Repository"))
#set($entityClass = $tableInfo.name)
##设置回调
$!callback.setFileName($tool.append($className, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/repository"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}repository;
$!autoImport
import $!{tableInfo.savePackageName}.repository.entity.$!{tableInfo.name};
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
*
* @author $author
* @since $!time.currTime()
*/
public interface $!{className} extends JpaRepository<$!{entityClass} , $!pk.shortType>, JpaSpecificationExecutor<$!{entityClass}> {
## @Modifying
## @Transactional
## void $tool.append("delete", $!{entityClass}, "ByIdIn")(List<String> ids);
}
service
##定义初始变量
#set($className = $tool.append($tableInfo.name, "Service"))
#set($pageValidatorClass = $tool.append("Page",$tableInfo.name, "Validator"))
#set($pageValidatorName = $tool.append("page",$tableInfo.name, "Validator"))
#set($entityClass = $tableInfo.name)
#set($entityName = $tool.firstLowerCase($tableInfo.name))
##设置回调
$!callback.setFileName($tool.append($className, ".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;
$!autoImport
import $!{tableInfo.savePackageName}.repository.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.validator.$pageValidatorClass;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务接口
*
* @author $!author
* @since $!time.currTime()
*/
public interface $!{className} {
/**
* 根据主键查询一条数据
*
* @param $!pk.name
*/
$!{entityClass} queryById($!pk.shortType $!pk.name);
/**
* 根据参数查询多条数据
*
* @param $!{entityName}
*/
List<$!{entityClass}> findByParam($!{entityClass} $!{entityName});
/**
* 保存一条数据
*
* @param $!{entityName}
*/
$!{entityClass} save($!{entityClass} $!{entityName});
/**
* 保存多条数据
*
* @param $!{entityName}s
*/
List<$!{entityClass}> save(List<$!{entityClass}> $!{entityName}s);
/**
* 分页查询,不带检索参数
*
* @param pageable
*/
Page<$!{entityClass}> page(Pageable pageable);
/**
* 分页查询,带检索参数
*
* @param $pageValidatorName
*/
Page<$!{entityClass}> page($pageValidatorClass $pageValidatorName);
/**
* 删除一条数据
*
* @param $!pk.name
*/
void deleteById($!pk.shortType $!pk.name);
/**
* 删除多条数据
*
* @param ids
*/
void deleteByIds(List<$!pk.shortType> ids);
}
serviceImpl
条件查询都要手动拼接可能出现的条件参数,太麻烦了。于是我写了一个根据反射拼接条件的方法。参考我的另一个帖子利用java反射动态拼接JPA查询条件
##定义初始变量
#set($entityClass = $tableInfo.name)
#set($entityName = $tool.firstLowerCase($tableInfo.name))
#set($class = $tool.append($entityClass, "ServiceImpl"))
#set($pageValidatorClass = $tool.append("Page",$tableInfo.name, "Validator"))
#set($pageValidatorName = $tool.append("page",$tableInfo.name, "Validator"))
##设置回调
$!callback.setFileName($tool.append($class, ".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;
$!autoImport
import $!{tableInfo.savePackageName}.repository.entity.$!{entityClass};
import $!{tableInfo.savePackageName}.repository.$!{entityClass}Repository;
import $!{tableInfo.savePackageName}.service.$!{entityClass}Service;
import $!{tableInfo.savePackageName}.validator.$pageValidatorClass;
import $!{tableInfo.savePackageName}.utils.JpaUtils;
import javax.persistence.criteria.Predicate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
/**
* $!{tableInfo.comment}($!{entityClass})表服务实现类
*
* @author $!author
* @since $!time.currTime()
*/
@Service("$!{entityName}Service")
public class $!{class} implements $!{entityClass}Service {
@Resource
private $!{entityClass}Repository $!{entityName}Repository;
@Override
public $!{entityClass} queryById($!pk.shortType $!pk.name) {
return this.$!{entityName}Repository.findOne($!pk.name);
}
/**
* 根据参数查询一条数据
*/
@Override
public List<$!{entityClass}> findByParam($!{entityClass} $!{entityName}) {
//构造自定义查询条件
// Root 用于获取属性字段,CriteriaQuery可以用于简单条件查询,CriteriaBuilder 用于构造复杂条件查询
Specification<$!{entityClass}> specification = (root, query, cb) -> {
// 该方法不适用于数字或者日期之间查询,如需查询要单独将条件加入predicateList
List<Predicate> predicateList = JpaUtils.getPredicateList($!{entityName}, root, cb);
return cb.and(predicateList.toArray(new Predicate[0]));
};
return $!{entityName}Repository.findAll(specification);
}
@Override
public Page<$!{entityClass}> page(Pageable pageable) {
return this.$!{entityName}Repository.findAll(pageable);
}
@Override
public Page<$!{entityClass}> page($pageValidatorClass $!{pageValidatorName}) {
Pageable pageable = new PageRequest($!{pageValidatorName}.getPageNumber() - 1, $!{pageValidatorName}.getPageSize()/*, Sort.Direction.DESC, "id"*/);
//构造自定义查询条件
return this.$!{entityName}Repository.findAll(new Specification<$!{entityClass}>(){
@Override
// Root 用于获取属性字段,CriteriaQuery可以用于简单条件查询,CriteriaBuilder 用于构造复杂条件查询
public Predicate toPredicate(Root<$!{entityClass}> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
//集合 用于封装查询条件
List<Predicate> list = new ArrayList<>();
// //简单单表查询
// if(StringUtils.isNotBlank($!{pageValidatorName}.getTccmc())){
// list.add(cb.like(root.get("tccmc").as(String.class),"%" + $!{pageValidatorName}.getTccmc()+ "%"));
// }
// if($!{pageValidatorName}.getUpdateTimeStart() != null && $!{pageValidatorName}.getUpdateTimeEnd() != null){
// list.add(cb.between(root.get("updateTime"), $!{pageValidatorName}.getUpdateTimeStart(), $!{pageValidatorName}.getUpdateTimeEnd()));
// }
// if($!{pageValidatorName}.getCreateTimeStart() != null && $!{pageValidatorName}.getCreateTimeEnd() != null){
// list.add(cb.between(root.get("createTime"), $!{pageValidatorName}.getCreateTimeStart(), $!{pageValidatorName}.getCreateTimeEnd()));
// }
##// //多表查询
##// Join<SecurityGroupInfo,Standard> standardJoin = root.join("standard", JoinType.INNER);
##// if(pageSecurityGroupInfoValidator.getStandard().getName()!=null){
##// list.add(cb.like(standardJoin.get("name").as(String.class),"%"+pageSecurityGroupInfoValidator.getStandard().getName()+"%" ));
##// }
return cb.and(list.toArray(new Predicate[0]));
}
},pageable);
}
@Override
public $!{entityClass} save($!{entityClass} $!{entityName}) {
##// if (StringUtils.isBlank($!{entityName}.getId())){
##// $!{entityName}.setCreateTime(Calendar.getInstance());
##// }
##// $!{entityName}.setUpdateTime(Calendar.getInstance());
return this.$!{entityName}Repository.save($entityName);
}
@Override
public List<$!{entityClass}> save(List<$!{entityClass}> $tool.append($!{entityName}, "s")) {
return this.$!{entityName}Repository.save($tool.append($!{entityName}, "s"));
}
@Override
public void deleteById($!pk.shortType $!pk.name) {
this.$!{entityName}Repository.delete($!pk.name);
}
@Override
public void deleteByIds(List<$!pk.shortType> $tool.append($!pk.name,"s")) {
ids.forEach(id -> {
this.$!{entityName}Repository.delete(id);
});
}
}
controller
##定义初始变量
#set($controllerClass = $tool.append($tableInfo.name, "Controller"))
#set($entityClass = $tableInfo.name)
#set($entityName = $tool.firstLowerCase($tableInfo.name))
#set($dotName = $tool.append($tool.firstLowerCase($tableInfo.name),"DTO"))
#set($dotClass = $tool.append($tableInfo.name, "DTO"))
#set($saveValidatorClass = $tool.append("Save",$tableInfo.name, "Validator"))
#set($saveValidatorName = $tool.append("save",$tableInfo.name, "Validator"))
#set($pageValidatorClass = $tool.append("Page",$tableInfo.name, "Validator"))
#set($pageValidatorName = $tool.append("page",$tableInfo.name, "Validator"))
#set($voClass = $tool.append($tableInfo.name, "VO"))
#set($voName = $tool.append($tableInfo.name, "Vo"))
#set($serviceClass = $tool.append($tableInfo.name, "Service"))
#set($serviceName = $tool.append($tool.firstLowerCase($tableInfo.name),"Service"))
##设置回调
$!callback.setFileName($tool.append($controllerClass, ".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;
$!autoImport
import $!{tableInfo.savePackageName}.repository.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$serviceClass;
import $!{tableInfo.savePackageName}.validator.$saveValidatorClass;
import $!{tableInfo.savePackageName}.validator.$pageValidatorClass;
import $!{tableInfo.savePackageName}.vo.$voClass;
import $!{tableInfo.savePackageName}.validator.DeleteDataStringValidator;
import $!{tableInfo.savePackageName}.validator.FindDataValidator;
import $!{tableInfo.savePackageName}.validator.SaveParkInfoValidator;
import com.hikvision.ga.common.BaseResult;
import com.hikvision.ga.logger.build.HikGaLoggerFactory;
import com.hikvision.ga.logger.log.HikGaLogger;
import com.hikvision.pbg.ctm01las.common.constants.enums.ActivitySecurityErrorCodeEnum;
import com.hikvision.pbg.ctm01las.common.constants.vo.PageResult;
import com.hikvision.pbg.ctm01las.tool.utils.JacksonTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.LinkedList;
import java.util.List;
/**
* $!{tableInfo.comment}($!{entityName})表控制层
*
* @author $!author
* @since $!time.currTime()
*/
@Api(tags = "$!{tableInfo.comment}")
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{controllerClass} {
private static final HikGaLogger logger = HikGaLoggerFactory.getLogger($!{controllerClass}.class);
/**
* 服务对象
*/
@Resource
private $serviceClass $serviceName;
/**
* 通过主键查询单条数据
*
* @param findDataValidator 查询参数
* @return 单条数据
*/
@ApiOperation(value = "通过主键查询单条数据", notes = "通过主键查询单条数据")
@PostMapping("getOne")
public BaseResult<$voClass> getOne(@Valid @RequestBody FindDataValidator findDataValidator) {
BaseResult<$voClass> baseResult;
try {
$entityClass $entityName = $!{serviceName}.queryById(findDataValidator.getId());
BeanCopier bc = BeanCopier.create($tool.append($entityClass,".class"), $tool.append($voClass,".class"), false);
$voClass $voName = new $voClass();
bc.copy($entityName,$voName,null);
baseResult = BaseResult.success($voName);
} catch (Exception e) {
logger.errorWithErrorCode(ActivitySecurityErrorCodeEnum.FIND_$!{tableInfo.obj.name}_BY_ID_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.UNKNOWN_ERROR.getEnMsg(), e);
return BaseResult.error(ActivitySecurityErrorCodeEnum.FIND_$!{tableInfo.obj.name}_BY_ID_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.FIND_$!{tableInfo.obj.name}_BY_ID_ERROR.getChMsg());
}
return baseResult;
}
/**
* 查询分页数据
*
* @param $pageValidatorName
* @return Page
*/
@PostMapping("page")
@ApiOperation(value = "查询分页数据", notes = "查询分页数据")
public BaseResult<PageResult<$voClass>> page(@Valid @RequestBody $pageValidatorClass $pageValidatorName) {
BaseResult baseResult;
try {
## 此处分页查询要注意:排序字段要以实体字段名为准,不能以数据库字段为准
Page<$entityClass> page = $!{serviceName}.page($pageValidatorName);
List<$entityClass> content = page.getContent();
List<$voClass> target = new LinkedList<>();
BeanCopier bc = BeanCopier.create($tool.append($entityClass,".class"), $tool.append($voClass,".class"), false);
content.forEach($entityName ->{
$voClass $voName = new $voClass();
bc.copy($entityName,$voName,null);
target.add($voName);
});
baseResult = BaseResult.success(PageResult.success(page.getTotalElements(), page.getTotalPages(), target));
} catch (Exception e) {
logger.errorWithErrorCode(ActivitySecurityErrorCodeEnum.PAGE_$!{tableInfo.obj.name}_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.UNKNOWN_ERROR.getEnMsg(), e);
return BaseResult.error(ActivitySecurityErrorCodeEnum.PAGE_$!{tableInfo.obj.name}_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.PAGE_$!{tableInfo.obj.name}_ERROR.getChMsg());
}
return baseResult;
}
/**
* 保存或更新一条数据
*
* @param $saveValidatorName 待保存数据
* @return 操作结果
*/
@ApiOperation(value = "保存或更新一条数据", notes = "保存或更新一条数据")
## @ApiImplicitParams({
###foreach($column in $tableInfo.fullColumn)
###if(${column.name}=="id")
###else
## @ApiImplicitParam(name = "$!{column.name}", value = "$!{column.comment}", required = true, dataType = "$!{tool.getClsNameByFullName($column.type)}"),
###end
###end
## })
@PostMapping("saveOne")
public BaseResult<Boolean> saveOne(@Valid @RequestBody $saveValidatorClass $saveValidatorName) {
BaseResult<Boolean> baseResult;
$entityClass $entityName = new $entityClass();
## $entityClass $tool.firstLowerCase($tableInfo.name) = new $entityClass();
try {
## BeanUtils.copyProperties($dotName,$tool.firstLowerCase($tableInfo.name));
## this.$!{tool.firstLowerCase($tableInfo.name)}Service.insert($tool.firstLowerCase($tableInfo.name));
BeanUtils.copyProperties($saveValidatorName,$entityName);
$!{serviceName}.save($entityName);
baseResult = BaseResult.success(true);
} catch (Exception e) {
logger.errorWithErrorCode(ActivitySecurityErrorCodeEnum.SAVE_$!{tableInfo.obj.name}_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.UNKNOWN_ERROR.getEnMsg(), e);
return BaseResult.error(ActivitySecurityErrorCodeEnum.SAVE_$!{tableInfo.obj.name}_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.SAVE_$!{tableInfo.obj.name}_ERROR.getChMsg());
}
return baseResult;
}
/**
* 通过主键删除数据
*
* @param deleteDataStringValidator 主键
* @return 操作结果
*/
@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
@DeleteMapping("deleteInfo")
public BaseResult<Boolean> delete(@RequestBody @Valid DeleteDataStringValidator deleteDataStringValidator) {
try {
$!{serviceName}.deleteByIds(deleteDataStringValidator.getIds());
return BaseResult.success(true);
} catch (Exception e) {
logger.errorWithErrorCode(ActivitySecurityErrorCodeEnum.DELETE_$!{tableInfo.obj.name}_BY_IDS_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.UNKNOWN_ERROR.getEnMsg(), e);
return BaseResult.error(ActivitySecurityErrorCodeEnum.DELETE_$!{tableInfo.obj.name}_BY_IDS_ERROR.getErrorCode(), ActivitySecurityErrorCodeEnum.DELETE_$!{tableInfo.obj.name}_BY_IDS_ERROR.getChMsg());
}
}
}
Dto
##定义初始变量
#set($className = $tool.append($tableInfo.name, "DTO"))
##设置回调
$!callback.setFileName($tool.append($className, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dto"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dto;
$!autoImport
import lombok.Data;
/**
* $!{tableInfo.comment}($!{tableInfo.name})DTO
*
* @author $!author
* @since $!time.currTime()
*/
@Data
public class $!{className} {
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})
/** ${column.comment}*/
#end
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
saveValidator
保存参数验证
##定义初始变量
#set($className = $tool.append("Save",$tableInfo.name, "Validator"))
#set($entityClass = $tableInfo.name)
##设置过滤字段。所填字段为数据库中字段。
#set($ignoreList = $tool.newArrayList("create_time","update_time"))
#foreach($item in $ignoreList)
#set($newList = $tool.newArrayList())
#foreach($column in $tableInfo.otherColumn)
#if($column.obj.name!=$item)
##带有反回值的方法调用时使用$tool.call来消除返回值
$tool.call($newList.add($column))
#end
#end
##重新保存
$tableInfo.setOtherColumn($newList)
#end
##设置回调
$!callback.setFileName($tool.append($className, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/validator"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}validator;
$!autoImport
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* $!{tableInfo.comment}($!{className})新增&更新校验对象
*
* @author $!author
* @since $!time.currTime()
*/
@Data
@ApiModel(value="$!{className}", description="新增&更新$!{tableInfo.comment}说明")
public class $!{className} {
#foreach($column in $tableInfo.pkColumn)
@ApiModelProperty(name = "$!{column.obj.name}", value = "$!{column.comment}", allowEmptyValue = true, example = "")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.otherColumn)
#set($notNull = $column.obj.notNull)
#if($notNull)
@NotNull(message = "传入参数$!{column.name}不能为空")
#end
#if($!{tool.getClsNameByFullName($column.type)} == "Integer")
@Min(value = 0, message = "参数$!{column.name}不能小于0")
#end
#if($!{tool.getClsNameByFullName($column.type)} == "Double")
@Digits(integer= 3, fraction = 8, message = "传入参数$!{column.name}经确度错误")
#end
@ApiModelProperty(name = "$!{column.name}", value = "$!{column.comment}", allowEmptyValue = #if($notNull)false#else true#end)
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
vo
##定义初始变量
#set($className = $tool.append($tableInfo.name, "VO"))
##设置回调
$!callback.setFileName($tool.append($className, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/vo"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}vo;
$!autoImport
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* $!{tableInfo.comment}($!{tableInfo.name})VO
*
* @author $!author
* @since $!time.currTime()
*/
@Data
@ApiModel(value="$!{className}", description="展示$!{tableInfo.comment}实体")
public class $!{className} {
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})
/** ${column.comment}*/
#end
@ApiModelProperty(name = "$!{column.name}", value = "$!{column.comment}")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
pageValidator
分页参数验证
##定义初始变量
#set($className = $tool.append("Page",$tableInfo.name, "Validator"))
##设置回调
$!callback.setFileName($tool.append($className, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/validator"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}validator;
$!autoImport
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
/**
* $!{tableInfo.comment}($!{className})新增&更新校验对象
*
* @author $!author
* @since $!time.currTime()
*/
@Data
@ApiModel(value="$!{className}", description="分页查询$!{tableInfo.comment}参数")
public class $!{className} {
@Min(value = 1 , message = "当前页码必须为正整数")
@ApiModelProperty(name = "pageNumber", value = "页码,从1开始", example = "1")
private Integer pageNumber;
@Min(value = 1 , message = "每页条数必须为正整数")
@ApiModelProperty(name = "pageSize", value = "每页数据条数", example = "20")
private Integer pageSize;
#foreach($column in $tableInfo.fullColumn)
#if($!{column.obj.name} == "create_time")
//
// @ApiModelProperty(name = "createTimeStart", value = "创建日期开始时间")
// private Date createTimeStart;
//
// @ApiModelProperty(name = "createTimeEnd", value = "创建日期结束时间")
// private Date createTimeEnd;
#elseif($!{column.obj.name} == "update_time")
//
// @ApiModelProperty(name = "updateTimeStart", value = "更新日期开始时间")
// private Date updateTimeStart;
//
// @ApiModelProperty(name = "updateTimeEnd", value = "更新日期结束时间")
// private Date updateTimeEnd;
#end
//
// @ApiModelProperty(name = "$!{column.name}", value = "$!{column.comment}")
// private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}