Entity层
{{ 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 {{=pkgName}}.entity.*;
import java.math.BigDecimal;
$blankline
/**
* {{=it.entity.defName}};{{=it.entity.comment}}
* @author : heimi
* @date : {{=fullYear}}-{{=month}}-{{=days}}
*/
@Data
public class {{=beanClass}} extends BaseEntity {
{{~it.entity.fields:field:index}}
/** {{=it.func.join(field.defName,field.comment,';')}} */
private {{=field.type}} {{=field.defKey}} ;
{{~}}
$blankline
}
Dao层(Mapper)
{{ 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}}.dao;
$blankline
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import cn.xzh.smart.core.annotataion.PageX;
import {{=pkgName}}.entity.*;
$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);
}
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}}.entity.*;
import {{=pkgName}}.dao.{{=beanClass}}Dao;
import java.util.List;
/**
* {{=it.entity.defName}};({{=it.entity.defKey}})表服务实现类
* @author : heimi
* @date : {{=fullYear}}-{{=month}}-{{=days}}
*/
@Service
public class {{=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);
}
}
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}}.entity.*;
import {{=pkgName}}.service.{{=serviceClass}};
import java.util.List;
$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);
}
}
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}}.dao.{{=beanClass}}Dao">
<resultMap type="{{=pkgName}}.entity.{{=beanClass}}" id="{{=beanClass}}Map">
{{~it.entity.fields:field:index}}
<result property="{{=field.defKey}}" 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="{{=field.defKey}} != null and {{=field.defKey}} != ''">
and {{=field.defKey}} = #{{{=field.defKey}}}
</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 '#{'+e.defKey+'}'}).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.'+e.defKey+'}'}).join(',')}})
</foreach>
</insert>
$blankline
<!-- 更新数据 -->
<update id="update">
update {{=it.entity.defKey}}
<set>
{{~it.entity.fields:field:index}}
<if test="{{=field.defKey}} != null and {{=field.defKey}} != ''">
{{=field.defKey}} = #{{{=field.defKey}}},
</if>
{{~}}
</set>
where {{=pkField}} = #{{{=pkVarName}}}
</update>
$blankline
<!--通过主键软删除-->
<update id="delete">
update {{=it.entity.defKey}} set status = 0 where {{=pkField}} = #{{{=pkVarName}}}
</update>
</mapper>
标签:创建,defKey,entity,field,PDManer,var,blankline,模板,beanClass
From: https://blog.csdn.net/2301_78701299/article/details/143887902