如下配置,可自动生成entity、controller、service、serviceImpl、dao、mapper文件
实现简单的CRUD接口
1、entity.java
##引入宏定义
$!define
##使用宏定义设置回调(保存位置与文件后缀)
#save("/model", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("model")
##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;
import lombok.Data;
##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
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
}
2、controller.java
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller/$!tool.firstLowerCase($!{tableInfo.name})"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller.$!{tool.firstLowerCase($!{tableInfo.name})};
import com.zjimee.boot.core.vo.requestParam.CommonRequest;
import com.zjimee.boot.rest.common.ResultCode;
import com.zjimee.boot.rest.constant.StatusCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zjimee.boot.core.model.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tool.firstLowerCase($!{tableInfo.name})}.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import com.zjimee.boot.rest.common.ResultCode;
import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表控制层
*
* @author wangj
* @since $!time.currTime()
*/
@RestController
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* 服务对象
*/
@Resource
private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
/**
* 通过主键查询单条数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 单条数据
*/
@GetMapping("/selectOne")
public ResultCode selectOne($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
try {
return this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryById($!tool.firstLowerCase($!{tableInfo.name}));
} catch (Exception e) {
return new ResultCode(StatusCode.Exception, "查询信息异常");
}
}
/**
* 条件查询
*
* @param request commonRequest
* @return 单条数据
*/
@PostMapping("/queryList")
public ResultCode queryList(HttpServletRequest request,@RequestBody CommonRequest commonRequest) {
try {
return this.$!{tool.firstLowerCase($!{tableInfo.name})}Service.queryList(request,commonRequest);
} catch (Exception e) {
return new ResultCode(StatusCode.Exception, "查询信息异常");
}
}
/**
* 新增信息
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return
*/
@PostMapping("/insert")
public ResultCode insert(HttpServletRequest request,@RequestBody $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
try {
return this.$!{tool.firstLowerCase($!{tableInfo.name})}Service.insert(request,$!tool.firstLowerCase($!{tableInfo.name}));
} catch (Exception e) {
return new ResultCode(StatusCode.Exception, "新增异常");
}
}
/**
* 修改信息
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return
*/
@PostMapping("/up