1.Model
{{ var today=new Date();
var fullYear=today.getFullYear();
var month=today.getMonth() + 1;
var days=today.getDate();
var pkVarName = "undefinedId";
var pkDataType = "String";
it.entity.fields.forEach(function(field){
if(field.primaryKey){
pkVarName = it.func.camel(field.defKey,false);
pkDataType = field["type"];
return;
}
});
var pkgName = it.entity.env.base.nameSpace;
var beanClass = it.entity.env.base.codeRoot;
var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
var serviceClass = beanClass+'Service';
var serviceVarName= beanVarName+'Service';
}}package {{=pkgName}}.entity;
$blankline
import java.time.LocalDateTime;
import lombok.Data;
import java.math.BigDecimal;
$blankline
/**
* {{=it.entity.defName}};{{=it.entity.comment}}
* @author : heimi
* @date : {{=fullYear}}-{{=month}}-{{=days}}
*/
@Data
public class {{=beanClass}} implements BaseModel {
{{~it.entity.fields:field:index}}
/** {{=it.func.join(field.defName,field.comment,';')}} */
private {{=field.type}} {{=it.func.camel(field.defKey,false)}} ;
{{~}}
$blankline
}
2.Dao
{{ var today=new Date();
var fullYear=today.getFullYear();
var month=today.getMonth() + 1;
var days=today.getDate();
var pkVarName = "undefinedId";
var pkDataType = "String";
it.entity.fields.forEach(function(field){
if(field.primaryKey){
pkVarName = it.func.camel(field.defKey,false);
pkDataType = field["type"];
return;
}
});
var pkgName = it.entity.env.base.nameSpace;
var beanClass = it.entity.env.base.codeRoot;
var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
var serviceClass = beanClass+'Service';
var serviceVarName= beanVarName+'Service';
}}package {{=pkgName}}.mapper;
$blankline
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import {{=pkgName}}.model.{{=beanClass}};
$blankline
/**
* {{=it.entity.defName}};({{=it.entity.defKey}})表数据库访问层
* @author : heimi
* @date : {{=fullYear}}-{{=month}}-{{=days}}
*/
@Mapper
public interface {{=beanClass}}Dao{
@PageX
List<{{=beanClass}}> select({{=beanClass}}Query query);
Integer insert({{=beanClass}} {{=beanVarName}});
Integer insertBatch(List<{{=beanClass}}> {{=beanVarName}}s);
Integer update({{=beanClass}} {{=beanVarName}});
Integer delete(Integer id);
}
3.Service
{{ var today=new Date();
var fullYear=today.getFullYear();
var month=today.getMonth() + 1;
var days=today.getDate();
var pkVarName = "undefinedId";
var pkVarNameU = "UndefinedId";
var pkDataType = "String";
it.entity.fields.forEach(function(field){
if(field.primaryKey){
pkVarName = it.func.camel(field.defKey,false);
pkVarNameU = it.func.camel(field.defKey,true);
pkDataType = field["type"];
return;
}
});
var pkgName = it.entity.env.base.nameSpace;
var beanClass = it.entity.env.base.codeRoot;
var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
var serviceClass = beanClass+'Service';
var serviceVarName= beanVarName+'Service';
var daoName = beanVarName+'Dao';
}}package {{=pkgName}}.service;
$blankline
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import {{=pkgName}}.model.{{=beanClass}};
import {{=pkgName}}.dao.{{=beanClass}}Dao;
import {{=pkgName}}.service.{{=serviceClass}};
/**
* {{=it.entity.defName}};({{=it.entity.defKey}})表服务实现类
* @author : heimi
* @date : {{=fullYear}}-{{=month}}-{{=days}}
*/
@Service
public class {{=serviceClass}}Impl implements {{=serviceClass}}{
$blankline
@Autowired
private {{=beanClass}}Dao {{=daoName}};
$blankline
public List<{{=beanClass}}> select({{=beanClass}}Query query) {
return {{=daoName}}.select(query);
}
$blankline
public Integer insert({{=beanClass}} {{=beanVarName}}) {
return {{=daoName}}.insert({{=beanVarName}});
}
$blankline
public Integer update({{=beanClass}} {{=beanVarName}}) {
return {{=daoName}}.update({{=beanVarName}});
}
$blankline
public Integer delete(Integer id) {
return {{=daoName}}.delete(id);
}
}
4.Controller
{{ var today=new Date();
var fullYear=today.getFullYear();
var month=today.getMonth() + 1;
var days=today.getDate();
var pkVarName = "undefinedId";
var pkDataType = "String";
it.entity.fields.forEach(function(field){
if(field.primaryKey){
pkVarName = it.func.camel(field.defKey,false);
pkDataType = field["type"];
return;
}
});
var pkgName = it.entity.env.base.nameSpace;
var beanClass = it.entity.env.base.codeRoot;
var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
var serviceClass = beanClass+'Service';
var serviceVarName= beanVarName+'Service';
}}package {{=pkgName}}.controller;
$blankline
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import {{=pkgName}}.model.{{=beanClass}};
import {{=pkgName}}.service.{{=serviceClass}};
$blankline
/**
* {{=it.entity.defName}};({{=it.entity.defKey}})控制层
* @author : heimi
* @date : {{=fullYear}}-{{=month}}-{{=days}}
*/
@RestController
@RequestMapping("/api/{{=beanVarName}}")
public class {{=beanClass}}Controller{
@Autowired
private {{=serviceClass}} {{=serviceVarName}};
$blankline
/**
* 查询接口
*/
@GetMapping
public List<{{=beanClass}}> select({{=beanClass}}Query query){
return {{=serviceVarName}}.select(query);
}
$blankline
@PostMapping
public Integer insert(@RequestBody {{=beanClass}} product){
return {{=serviceVarName}}.insert(product);
}
$blankline
@PutMapping
public Integer update(@RequestBody {{=beanClass}} product){
return {{=serviceVarName}}.update(product);
}
$blankline
@DeleteMapping
public Integer delete(Integer id){
return {{=serviceVarName}}.delete(id);
}
}
5.Mapper.xml
{{ var today=new Date();
var fullYear=today.getFullYear();
var month=today.getMonth() + 1;
var days=today.getDate();
var pkVarName = "undefinedId";
var pkDataType = "String";
var pkField = "UNDEFINED_ID";
it.entity.fields.forEach(function(field){
if(field.primaryKey){
pkField = field.defKey;
pkVarName = it.func.camel(field.defKey,false);
pkDataType = field["type"];
return;
}
});
var pkgName = it.entity.env.base.nameSpace;
var beanClass = it.entity.env.base.codeRoot;
var beanVarName = beanClass.charAt(0).toLowerCase()+beanClass.slice(1);
var serviceClass = beanClass+'Service';
var serviceVarName= beanVarName+'Service';
}}<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="{{=pkgName}}.mapper.{{=beanClass}}Mapper">
<resultMap type="{{=pkgName}}.model.{{=beanClass}}" id="{{=beanClass}}Map">
{{~it.entity.fields:field:index}}
<result property="{{=it.func.camel(field.defKey,false)}}" column="{{=field.defKey}}" />
{{~}}
</resultMap>
$blankline
$blankline
<!--通用查询-->
<select id="select" resultMap="{{=beanClass}}Map">
select
{{=it.entity.fields.map(function(e,i){return e.defKey}).join(',')}}
from {{=it.entity.defKey}}
<where>
{{~it.entity.fields:field:index}}
<if test="{{=it.func.camel(field.defKey,false)}} != null and {{=it.func.camel(field.defKey,false)}} != ''">
and {{=field.defKey}} = #{{{=it.func.camel(field.defKey,false)}}}
</if>
{{~}}
</where>
</select>
$blankline
<!--新增数据-->
<insert id="insert" keyProperty="{{=pkField}}" useGeneratedKeys="true">
insert into {{=it.entity.defKey}}({{=it.entity.fields.map(function(e,i){return e.defKey}).join(',')}})
values ({{=it.entity.fields.map(function(e,i){return '#{'+it.func.camel(e.defKey,false)+'}'}).join(',')}})
</insert>
$blankline
<!-- 批量新增数据 -->
<insert id="insertBatch" keyProperty="{{=pkField}}" useGeneratedKeys="true">
insert into {{=it.entity.defKey}}({{=it.entity.fields.map(function(e,i){return e.defKey}).join(',')}})
values
<foreach collection="entities" item="entity" separator=",">
({{=it.entity.fields.map(function(e,i){return '#{entity.'+it.func.camel(e.defKey,false)+'}'}).join(',')}})
</foreach>
</insert>
$blankline
<!-- 更新数据 -->
<update id="update">
update {{=it.entity.defKey}}
<set>
{{~it.entity.fields:field:index}}
<if test="{{=it.func.camel(field.defKey,false)}} != null and {{=it.func.camel(field.defKey,false)}} != ''">
{{=field.defKey}} = #{{{=it.func.camel(field.defKey,false)}}},
</if>
{{~}}
</set>
where {{=pkField}} = #{{{=pkVarName}}}
</update>
$blankline
<!--通过主键软删除-->
<update id="delete">
update {{=it.entity.defKey}} set status = 0 where {{=pkField}} = #{{{=pkVarName}}}
</update>
</mapper>