easycode模板

blade-entity.java

##导入宏定义
$!define
##保存文件(宏定义)
#save("/entity", ".java")
##包路径(宏定义)
#setPackageSuffix("entity")
##自动导入包(全局变量)
$!autoImport

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

##表注释(宏定义)
#tableComment("表实体类")
@Data
@Builder
@TableName("$!{tableInfo.obj.name}")
public class $!{tableInfo.name} implements Serializable {

    private static final long serialVersionUID = 1L;

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    #if($column.name.equals('id'))@TableId(type = IdType.ASSIGN_ID)#end
    #if($column.name.equals('id') || ${column.name.indexOf("Id")}!=-1)@JsonSerialize(using = ToStringSerializer.class)#end
    #if($column.name.equals('isDeleted'))@TableLogic#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};

#end
}

blade-dao.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Mapper")
##保存文件(宏定义)
#save("/mapper", "Mapper.java")
##包路径(宏定义)
#setPackageSuffix("mapper")

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import org.apache.ibatis.annotations.Mapper;

##表注释(宏定义)
#tableComment("表数据库访问层")
@Mapper
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {

}

blade-service.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Service")
##保存文件(宏定义)
#save("/service", "Service.java")
##包路径(宏定义)
#setPackageSuffix("service")

import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.req.$!{tableInfo.name}FindReq;
import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}Vo;
import $!{tableInfo.savePackageName}.vo.base.PageData;

import java.util.List;

##表注释(宏定义)
#tableComment("表服务接口")
public interface $!{tableName} extends IService<$!tableInfo.name> {
    /**
     * 列表分页查询
     *
     * @param req
     * @return
     */
    PageData<$!{tableInfo.name}Vo> listWithPage($!{tableInfo.name}FindReq req);

    /**
     * 列表查询
     *
     * @param req
     * @return
     */
    List<$!{tableInfo.name}Vo> listWithoutPage($!{tableInfo.name}FindReq req);

    /**
     * po to vo
     *
     * @param po
     * @return
     */
    $!{tableInfo.name}Vo toVo($!{tableInfo.name} po);

    /**
     * po list to vo list
     *
     * @param poList
     * @return
     */
    List<$!{tableInfo.name}Vo> toVoList(List<$!{tableInfo.name}> poList);
}

blade-serviceImpl.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")
##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java")
##包路径(宏定义)
#setPackageSuffix("service.impl")

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.req.$!{tableInfo.name}FindReq;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}Vo;
import $!{tableInfo.savePackageName}.vo.base.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.error.BuErr;
import org.springblade.common.exception.BizException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

##表注释(宏定义)
#tableComment("表服务实现类")
@Slf4j
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {
    @Override
    public PageData<$!{tableInfo.name}Vo> listWithPage($!{tableInfo.name}FindReq req) {
        Page page = null;
        if (req.getPageNum() > 0 && req.getPageSize() > 0) { // 分页
            page = PageHelper.startPage(req.getPageNum(), req.getPageSize());
        }
        List<$!{tableInfo.name}Vo> list = listWithoutPage(req);
        return new PageData<$!{tableInfo.name}Vo>(list, page);
    }

    @Override
    public List<$!{tableInfo.name}Vo> listWithoutPage($!{tableInfo.name}FindReq req) {
        LambdaQueryWrapper<$!{tableInfo.name}> condition = new LambdaQueryWrapper<$!{tableInfo.name}>();
        List<$!{tableInfo.name}> list = list(condition);
        return toVoList(list);
    }

    @Override
    public $!{tableInfo.name}Vo toVo($!{tableInfo.name} po) {
        if(null == po){
            throw new BizException(BuErr.EMPTY_BILL.getCode(), BuErr.EMPTY_BILL.getMsg());
        }
        return $!{tableInfo.name}Vo.builder()
        #foreach($column in $tableInfo.fullColumn)
                .$!{column.name}(po.get$!{tool.firstUpperCase($!{column.name})}())
        #end
                .build();
    }

    @Override
    public List<$!{tableInfo.name}Vo> toVoList(List<$!{tableInfo.name}> poList) {
        return poList.parallelStream().map(e -> toVo(e)).collect(Collectors.toList());
    }
}

blade-controller.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Controller")
##保存文件(宏定义)
#save("/controller", "Controller.java")
##包路径(宏定义)
#setPackageSuffix("controller")
##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.req.$!{tableInfo.name}AddReq;
import $!{tableInfo.savePackageName}.req.$!{tableInfo.name}EditReq;
import $!{tableInfo.savePackageName}.req.$!{tableInfo.name}FindReq;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}Vo;
import $!{tableInfo.savePackageName}.vo.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

##表注释(宏定义)
#tableComment("表控制层")
@RestController
@RequestMapping(value = "$!entityName", produces = "application/json; charset=utf-8")
@Validated
@Api(tags = "todo")
public class $!{tableName} {
  
    /**
     * 服务对象
     */
    @Autowired
    $!{tableInfo.name}Service $!{serviceName};   
        
    /**
     * 新增数据
     *
     * @param req 实体对象
     * @return 新增结果
     */
    @ApiOperation("【app|web】新增数据")
    @PostMapping("/add")
    @SneakyThrows(Exception.class)
    public R save(@Validated @RequestBody $!{tableInfo.name}AddReq req) {
        return R.status($!{serviceName}.save(req.toAddPo())); 
    }

    /**
     * 删除
     *
     * @param ids 主键集合
     * @return 删除结果
     */
    @ApiOperation("【app|web】删除")
    @ApiImplicitParams({
            @ApiImplicitParam(required = true, name = "ids", value = "id以逗号隔开", paramType = "query", dataType = "String")
    })
    @PostMapping("/remove") 
    @SneakyThrows(Exception.class)
    public R remove(@NotNull @RequestParam("ids") String ids) {
        return R.status($!{serviceName}.removeByIds(Func.toLongList(ids))); 
    }
    
    /**
     * 修改数据
     *
     * @param req 实体对象
     * @return 修改结果
     */
    @ApiOperation("【app|web】修改数据")
    @PutMapping("/update") 
    @SneakyThrows(Exception.class)
    public R update(@Validated @RequestBody $!{tableInfo.name}EditReq req) {
        return R.status($!{serviceName}.updateById(req.toEditPo())); 
    }
        
    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("【app|web】详情")
    @ApiImplicitParams({
            @ApiImplicitParam(required = true, name = "id", value = "id", paramType = "query", dataType = "Long")
    })
    @GetMapping("/detail") 
    @SneakyThrows(Exception.class)
    public R<$!{tableInfo.name}Vo> detail(@NotNull @RequestParam("id") Long id) {
        $!{tableInfo.name} one = $!{serviceName}.getById(id);
        return R.data($!{serviceName}.toVo(one));
    }
      
    /**
     * 分页查询
     *
     * @param req 查询实体
     * @return 所有数据
     */
    @ApiOperation("【app|web】分页查询")
    @GetMapping("/page") 
    @SneakyThrows(Exception.class)
    public R> page(@Validated @RequestBody $!{tableInfo.name}FindReq req) {
        return R.data($!{serviceName}.listWithPage(req));
    }
}

blade-addreq.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("AddReq")
##保存文件(宏定义)
#save("/req", "AddReq.java")
##包路径(宏定义)
#setPackageSuffix("req")
##自动导入包(全局变量)
$!autoImport

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.secure.utils.AuthUtil;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

##表注释(宏定义)
#tableComment("创建请求实体类")
@Data
@ApiModel(value = "$!{tableInfo.obj.name}创建请求", description = "$!{tableInfo.obj.name}创建请求")
public class $!{tableInfo.name}AddReq implements Serializable {

    private static final long serialVersionUID = 1L;

#foreach($column in $tableInfo.fullColumn)
  ## 跳过id字段
  #if(!$column.name.equals('id'))
    ## 开始设置每个属性
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    @ApiModelProperty(required = true, value = "${column.comment}")
    ## 设置校验注解
    #if($!{tool.getClsNameByFullName($column.type)} == "String")
    @NotBlank(message = "${column.comment}不可为空")
    @Size(min = 1, max = 20, message = "${column.comment}的长度为1~20个字符")
    #else
    @NotNull(message = "${column.comment}不可为空")
    #end
    ## 属性
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
  #end 
#end

## 设置toPo方法
    public $!{tableInfo.name} toAddPo() {
        Long currentUserId = AuthUtil.getUserId();
        String currentUserName = AuthUtil.getUserName();
        Date now = new Date();
        return $!{tableInfo.name}.builder()
        #foreach($column in $tableInfo.fullColumn)
          ## 跳过id字段
          #if(!$column.name.equals('id'))
                #if($column.name.equals('createUser'))
                .createUser(currentUserId)
                #elseif($column.name.equals('createUserName'))
                .createUserName(createUserName)
                #elseif($column.name.equals('createTime'))
                .createTime(now)
                #elseif($column.name.equals('updateUser'))
                .updateUser(currentUserId)
                #elseif($column.name.equals('updateUserName'))
                .updateUserName(currentUserName)
                #elseif($column.name.equals('updateTime'))
                .updateTime(now)
                #elseif($column.name.equals('isDeleted'))
                .isDeleted(false)
                #else
                .$!{column.name}($!{column.name})
                #end
          #end
        #end
                .build();
    }
}


blade-editreq.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("EditReq")
##保存文件(宏定义)
#save("/req", "EditReq.java")
##包路径(宏定义)
#setPackageSuffix("req")
##自动导入包(全局变量)
$!autoImport

import java.util.Date;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.secure.utils.AuthUtil;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;

##表注释(宏定义)
#tableComment("更新请求实体类")
@Data
@ApiModel(value = "$!{tableInfo.obj.name}更新请求", description = "$!{tableInfo.obj.name}更新请求")
public class $!{tableInfo.name}EditReq implements Serializable {

    private static final long serialVersionUID = 1L;

#foreach($column in $tableInfo.fullColumn)
    ## 开始设置每个属性
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    @ApiModelProperty(required = true, value = "${column.comment}")
    ## 设置校验注解
    #if($!{tool.getClsNameByFullName($column.type)} == "String")
    @NotBlank(message = "${column.comment}不可为空")
    @Size(min = 1, max = 20, message = "${column.comment}的长度为1~20个字符")
    #else
    @NotNull(message = "${column.comment}不可为空")
    #end
    ## 属性
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end

## 设置toPo方法
    public $!{tableInfo.name} toEditPo() {
        Long currentUserId = AuthUtil.getUserId();
        String currentUserName = AuthUtil.getUserName();
        Date now = new Date();
        return $!{tableInfo.name}.builder()
        #foreach($column in $tableInfo.fullColumn)
                #if($column.name.equals('updateUser'))
                .updateUser(currentUserId)
                #elseif($column.name.equals('updateUserName'))
                .updateUserName(currentUserName)
                #elseif($column.name.equals('updateTime'))
                .updateTime(now)
                #else
                .$!{column.name}($!{column.name})
                #end
        #end
                .build();
    }
}

blade-findreq.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("FindReq")
##保存文件(宏定义)
#save("/req", "FindReq.java")
##包路径(宏定义)
#setPackageSuffix("req")
##自动导入包(全局变量)
$!autoImport

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

##表注释(宏定义)
#tableComment("查询请求实体类")
@Data
@ApiModel(value = "$!{tableInfo.obj.name}查询请求", description = "$!{tableInfo.obj.name}查询请求")
public class $!{tableInfo.name}FindReq implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(required = true, value = "第几页")
    private Integer pageNum;

    @ApiModelProperty(required = true, value = "页容量")
    private Integer pageSize;
    
#foreach($column in $tableInfo.fullColumn)
    ## 开始设置每个属性
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    @ApiModelProperty(required = false, value = "${column.comment}")
    ## 属性
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}


blade-vo.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Vo")
##保存文件(宏定义)
#save("/vo", "Vo.java")
##包路径(宏定义)
#setPackageSuffix("vo")
##自动导入包(全局变量)
$!autoImport

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

##表注释(宏定义)
#tableComment("响应实体类")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "$!{tableInfo.obj.name}响应", description = "$!{tableInfo.obj.name}响应")
public class $!{tableInfo.name}Vo implements Serializable {

    private static final long serialVersionUID = 1L;

#foreach($column in $tableInfo.fullColumn)
    ## 开始设置每个属性
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    @ApiModelProperty(required = false, value = "${column.comment}")
    ## 属性
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}


blade-excel.java

##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Excel")
##保存文件(宏定义)
#save("/excel", "Excel.java")
##包路径(宏定义)
#setPackageSuffix("excel")
##自动导入包(全局变量)
$!autoImport

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

##表注释(宏定义)
#tableComment("导出实体类")
@Data
@ColumnWidth(20)
@HeadRowHeight(20)
@ContentRowHeight(18)
@ApiModel(value = "$!{tableInfo.obj.name} Excel实体类", description = "$!{tableInfo.obj.name} Excel实体类")
public class $!{tableInfo.name}Excel implements Serializable {

    private static final long serialVersionUID = 1L;

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    @ApiModelProperty(required = true, value = "${column.comment}")
    @ExcelProperty("${column.comment}")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}

你可能感兴趣的:(easycode模板)