easyCode生成代碼配置

使用方法:

配置數據庫-》選擇想要操作的表-》右鍵選擇

然後選擇要生成的代碼,

下面針對自己的項目做定製化配置:

全局配置去掉表前綴:

配置生成的實體類,接口規則:

entity.java配置:

##引入宏定義
$!init
$!define

##使用宏定義設置回調(保存位置與文件後綴)
#save("/entity", ".java")

##使用宏定義設置包後綴
#setPackageSuffix("entity")

##使用全局變量實現默認包導入
$!autoImport
import java.io.Serializable;

##使用宏定義實現類註釋信息
#tableComment("實體類")
public class $!{tableInfo.name} implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})
    /**
      *${column.comment}
      */
    #end

    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end

#foreach($column in $tableInfo.fullColumn)
##使用宏定義實現get,set方法
#getSetMethod($column)
#end

}

 service.java配置:

##定義初始變量
$!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 com.osmagic.commons.basic.BaseService;
import com.osmagic.commons.entity.$!{tableInfo.name};
import java.util.List;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服務接口
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName} extends BaseService<$!{tableInfo.name}> {

   
}

serviceImpl.java配置:

##定義初始變量
$!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

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

import com.osmagic.commons.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import com.osmagic.commons.basic.ResponseApi;
import javax.annotation.Resource;
import java.util.List;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服務實現類
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Service
public class $!{tableName} implements $!{tableInfo.name}Service {

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

   @Override
    public ResponseApi find($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})) {
        return null;
    }

    @Override
    public ResponseApi detail($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})) {
        return null;
    }

    @Override
    public ResponseApi insert( $!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})) {
        return null;
    }

    @Override
    public ResponseApi update( $!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})) {
        return null;
    }

    @Override
    public ResponseApi delete( $!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name})) {
        return null;
    }
  
}

controller.java配置:

##定義初始變量
$!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}rest;


import com.osmagic.commons.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import com.osmagic.commons.basic.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.osmagic.commons.basic.ResponseApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服務接口
 *
 * @author $!author
 * @since $!time.currTime()
 */
 @RestController
@RequestMapping("/api/v1/")
public class $!{tableName} implements BaseController<$!{tableInfo.name}> {

       @Autowired
       private $!{tableInfo.name}Service $tool.firstLowerCase($!{tableInfo.name})Service;
       
    @Override
    public ResponseApi find($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}), BindingResult result) {
        return $tool.append($tool.firstLowerCase($!{tableInfo.name}),"Service.find(",$tool.firstLowerCase($!{tableInfo.name}),")");
    }

    @Override
    public ResponseApi detail($!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}), BindingResult result) {
        return $tool.append($tool.firstLowerCase($!{tableInfo.name}),"Service.detail(",$tool.firstLowerCase($!{tableInfo.name}),")");
    }

    @Override
    public ResponseApi insert(@RequestBody $!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}), BindingResult result) {
        return $tool.append($tool.firstLowerCase($!{tableInfo.name}),"Service.insert(",$tool.firstLowerCase($!{tableInfo.name}),")");
    }

    @Override
    public ResponseApi update(@RequestBody $!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}), BindingResult result) {
        return $tool.append($tool.firstLowerCase($!{tableInfo.name}),"Service.update(",$tool.firstLowerCase($!{tableInfo.name}),")");
    }

    @Override
    public ResponseApi delete(@RequestBody $!{tableInfo.name} $tool.firstLowerCase($!{tableInfo.name}), BindingResult result) {
        return $tool.append($tool.firstLowerCase($!{tableInfo.name}),"Service.delete(",$tool.firstLowerCase($!{tableInfo.name}),")");
    }
}

mapper.java配置:

##定義初始變量
$!init
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##設置回調
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))

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

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

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

/**
 *($!{tableInfo.name})表服務實現類
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Mapper
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}> {
    
   
  
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章