easy code生成代码(jpa模板)并匹配swagger2

目的

给我一张表,只需要两分钟就能生成接口。开发效率大幅度提高有木有。

资料

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
}

类型转换

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,681评论 5 474
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,710评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,623评论 0 334
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,202评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,232评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,368评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,795评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,461评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,647评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,476评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,525评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,226评论 3 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,785评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,857评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,090评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,647评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,215评论 2 341

推荐阅读更多精彩内容