Spring Boot 개발 도구 EasyCode 플러그 인,코드 역방향 템 플 릿

17979 단어 Java

엔 터 티 템 플 릿
##     
##   t_   
$!init
$!define

##         (         )
#save("/entity", ".java")

##          
#setPackageSuffix("entity")

##    
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0).name)
#end
import $!{tableInfo.savePackageName}.util.QueryRequest;
##             
$!autoImport
import java.io.Serializable;
import io.swagger.annotations.*;
import lombok.Data;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
 
##            
#tableComment("   ")
@Data
@Table(name = "$!tableInfo.obj.name")
@ApiModel("$tableInfo.comment")
public class $!{tableInfo.name} extends QueryRequest implements Serializable {
 
    private static final long serialVersionUID = $!tool.serial();
    
#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    ##            
    #if(${column.name.equals($pk)})
 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)#end
    
    @ApiModelProperty("$column.comment")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}

dao.mapper
##   t_   
$!init
##      
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##    
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao/mapper"))

##    
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao.mapper;

import $!{tableInfo.savePackageName}.base.TkBaseMapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};

/**
 * $!{tableInfo.comment}($!{tableInfo.name})       
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName} extends TkBaseMapper {

}

서비스 템 플 릿
##   t_   
$!init
##      
#set($tableName = $tool.append($tableInfo.name, "Service"))
##    
$!callback.setFileName($tool.append($tableName, ".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;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import java.util.List;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})      
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName} {

    /**
     *     
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    int save(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     *     
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    int insert(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     *         
     *
     * @param userId   ID
     * @param $!pk.name   
     * @return     
     */
    int delete(Integer userId, $!pk.shortType $!pk.name);

    /**
     *     
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     *   ID      
     *
     * @param $!pk.name   
     * @return     
     */
    $!{tableInfo.name} queryById($!pk.shortType $!pk.name);

    /**
     *       
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    PageWrapper list(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
}

serviceImpl.java
##   t_   
$!init
##      
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##    
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))

##    
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

##  createBy  
#if(!$tableInfo.otherColumn.isEmpty())
    #foreach($column in $tableInfo.otherColumn)
        #if($column.name.equals("createBy"))
            #set($createBy = $column.name)
        #end
        #if($column.name.equals("updateBy"))
            #set($updateBy = $column.name)
        #end
        #if($column.name.equals("updateTime"))
            #set($updateTime = $column.name)
        #end
        #if($column.name.equals("flag"))
            #set($flag = $column.name)
        #end
    #end
#end

##             
#set($length1 = $tool.firstLowerCase($!{tableInfo.name}).substring(0, 1))

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;

import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.enums.DataEnum;
import $!{tableInfo.savePackageName}.dao.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import java.util.Date;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import java.util.List;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})      
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
public class $!{tableName} implements $!{tableInfo.name}Service {

    /**
     *     
     */
    @Resource
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;

    /**
     *     
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    @Override
    public int save(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        if($!{tool.firstLowerCase($!{tableInfo.name})}.get$!{tool.firstUpperCase($!{pk.name})}() == null){
            return insert(userId, $!tool.firstLowerCase($!{tableInfo.name}));
        } else {
            return update(userId,$!tool.firstLowerCase($!{tableInfo.name}));
        }
    }

    /**
     *     
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    @Override
    public int insert(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        $!{tool.firstLowerCase($!{tableInfo.name})}.set$!{tool.firstUpperCase($!{createBy})}(userId);
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insertSelective($!tool.firstLowerCase($!{tableInfo.name}));
    }

    /**
     *         
     *
     * @param userId   ID
     * @param $!pk.name   
     * @return     
     */
    @Override
    public int delete(Integer userId, $!pk.shortType $!pk.name) {
		$!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.selectByPrimaryKey($!pk.name);
        $!{tool.firstLowerCase($!{tableInfo.name})}.set$!{tool.firstUpperCase($!{updateBy})}(userId);
        $!{tool.firstLowerCase($!{tableInfo.name})}.set$!{tool.firstUpperCase($!{updateTime})}(new Date());
        $!{tool.firstLowerCase($!{tableInfo.name})}.set$!{tool.firstUpperCase($!{flag})}(DataEnum.FLAG_STATUS_INVALID.getCode());
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.updateByPrimaryKeySelective($!tool.firstLowerCase($!{tableInfo.name}));
    }

    /**
     *     
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    @Override
    public int update(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})){
		$!{tableInfo.name} $!{length1} = $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.selectByPrimaryKey($!{tool.firstLowerCase($!{tableInfo.name})}.get$!{tool.firstUpperCase($!{pk.name})}());
		// FIXME    
        return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.updateByPrimaryKeySelective($!{length1});
	}

    /**
     *   ID      
     *
     * @param $!pk.name   
     * @return     
     */
    @Override
    public Blacklist queryById($!pk.shortType $!pk.name){
		return $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.selectByPrimaryKey($!pk.name);
	}

    /**
     *       
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    @Override
    public PageWrapper list(Integer userId, $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        PageHelper.startPage($!{tool.firstLowerCase($!{tableInfo.name})}.getPageNum(), $!{tool.firstLowerCase($!{tableInfo.name})}.getPageSize());
        $!{tool.firstLowerCase($!{tableInfo.name})}.set$!{tool.firstUpperCase($!{flag})}(DataEnum.FLAG_STATUS_VALID.getCode());
        PageInfo page = new PageInfo<>($!{tool.firstLowerCase($!{tableInfo.name})}Mapper.select($!{tool.firstLowerCase($!{tableInfo.name})}));
        PageHelper.clearPage();
        return new PageWrapper<>(page);
    }
}

controller.java
##   t_   
$!init
##      
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##    
$!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 $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import com.example.dolabor20200513.vo.ResponseHelper;
import com.example.dolabor20200513.vo.ResponseModel;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})    
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})") 
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {

    /**
     *     
     */
    @Resource
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

    /**
     *   /    
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    @PostMapping("save")
    @ApiOperation(value = "  /  ", notes = "  /  $!{tableInfo.comment}     ")
    @RequiresPermissions(logical = Logical.OR, value = {"$!tool.firstLowerCase($!{tableInfo.name}):insert", "$!tool.firstLowerCase($!{tableInfo.name}):edit"})
    public ResponseModel save(@UserId String userId, @RequestBody @Valid $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
            return ResponseHelper.success($!{tool.firstLowerCase($!{tableInfo.name})}Service.save(Integer.valueOf(userId), $!tool.firstLowerCase($!{tableInfo.name})));
    }

    /**
     *         
     *
     * @param userId   ID
     * @param $!pk.name   
     * @return     
     */
    @PostMapping("delete")
    @ApiOperation(value = "  ", notes = "  $!{tableInfo.comment}     ")
    @RequiresPermissions(logical = Logical.OR, value = {"$!tool.firstLowerCase($!{tableInfo.name}):delete"})
    public ResponseModel delete(@UserId String userId, $!pk.shortType $!pk.name) {
            return ResponseHelper.success($!{tool.firstLowerCase($!{tableInfo.name})}Service.delete(Integer.valueOf(userId), $!pk.name));
    }

    /**
     *       
     *
     * @param userId   ID
     * @param $!tool.firstLowerCase($!{tableInfo.name})     
     * @return     
     */
    @PostMapping("list")
    @ApiOperation(value = "  ", notes = "  $!{tableInfo.comment}     ")
    public ResponseModel list(@UserId String userId, @RequestBody $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        return ResponseHelper.success($!{tool.firstLowerCase($!{tableInfo.name})}Service.list(Integer.valueOf(userId), $!tool.firstLowerCase($!{tableInfo.name})));
    }

}

ResponseModel.java
package com.example.dolabor20200513.vo;

import com.example.dolabor20200513.enums.ResultCode;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;

/**
 * @author pc
 *            
 */
public class ResponseModel implements Serializable {

    private static final long serialVersionUID = -1241360949457314497L;
    private T data;
    private String message;
    private Integer code;

    public ResponseModel() {
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getResponse();
        response.setCharacterEncoding("UTF-8");
    }

    public ResponseModel(T data, ResultCode resultCode) {
        this.data = data;
        this.message = resultCode.getMessage();
        this.code = resultCode.getCode();
    }

    public String getMessage() {
        return this.message;
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T result) {
        this.data = result;
    }

    @Override
    public String toString() {
        return "ResponseModel [ result=" + this.data +  ", message=" + this.message + ", code=" + this.code + "]";
    }
}
ResultCode.java
package com.example.dolabor20200513.enums;

import lombok.Getter;

/**
 * @author BaoBao
 */
@Getter
public enum ResultCode {

    //     
    SUCCESS(10000, "    "),
    FAILED(10001, "    "),
    VALIDATE_FAILED(10002, "      "),

    //     
    ACCOUNT_LOCKED(20000, "      ,    "),
    ACCOUNT_ERROR(20001, "       "),
    IDENTIFICATION_ERROR(20002,"    "),
    LOGIN_STATE_EXPIRED(2004, "    ,     "),

    //     
    NULL_POINTER(10003, "     "),
    IOE_POINTER(10004, "JACKSON    "),
    INDEX_OUT_OF_BOUNDS(10004, "  (  )      "),
    SEND_MSG_ERROR(10005, "       "),

    //     
    ERROR(50000, "    ");

    /**
     *      
     */
    private Integer code;

    /**
     *       
     */
    private String message;

    ResultCode(int code, String message){
        this.code = code;
        this.message = message;
    }
}

ResponseHelper.java 
package com.example.dolabor20200513.vo;

import com.example.dolabor20200513.enums.ResultCode;

import java.io.Serializable;

/**
 *         
 * @author pc
 */
public class ResponseHelper implements Serializable {

    /**
     *       : code + msg
     * @param model
     * @param 
     * @return
     */
    public static  ResponseModel success(T model) {
        return successWith(model, ResultCode.SUCCESS);
    }

    /**
     *         : code + msg
     * @param t
     * @param resultCode
     * @param 
     * @return
     */
    public static  ResponseModel successWith(T t, ResultCode resultCode) {
        return new ResponseModel(t, resultCode);
    }

    /**
     *       : code + msg
     * @param model
     * @param 
     * @return
     */
    public static  ResponseModel failed(T model) {
        return failedWith(model, ResultCode.ERROR);
    }

    /**
     *          : code + msg
     * @param t
     * @param resultCode
     * @param 
     * @return
     */
    public static  ResponseModel failedWith(T t, ResultCode resultCode) {
        return new ResponseModel<>(t, resultCode);
    }
}

QueryRequest .java
package com.example.dolabor20200513.util;

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

import javax.persistence.Transient;
import java.io.Serializable;

/**
 * @author pc
 */
@Data
public class QueryRequest implements Serializable {
    @Transient
    private static final long serialVersionUID = -4869594085374385813L;

    @Transient
    private int pageSize = 10;
    @Transient
    private int pageNum = 1;

    @ApiModelProperty(name = "userType", value = "      ")
    @Transient
    private String userType;
    @Transient
    private String sortField;
    @Transient
    private String sortOrder;
}
DeleteDataUtil.java
package com.example.dolabor20200513.util;

import lombok.Getter;

import javax.validation.constraints.NotNull;

/**
 *       
 * @author pc
 */
@Getter
public class DeleteDataUtil {

    @NotNull
    private Integer id;

    @NotNull
    private Integer flag;
}
TkBaseMapper.java
package com.example.dolabor20200513.base;

import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.ExampleMapper;
import tk.mybatis.mapper.common.MySqlMapper;

/**
 * TK   
 * @author pc
 * @param 
 */
public interface TkBaseMapper extends BaseMapper, ExampleMapper, MySqlMapper {
}

좋은 웹페이지 즐겨찾기