mirror of https://gitee.com/makejava/EasyCode.git
Merge branch 'master' of https://github.com/makejavas/EasyCode
This commit is contained in:
commit
32b7f77d94
|
@ -57,6 +57,22 @@ public interface $!{tableName} {
|
|||
*/
|
||||
int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<$!{tableInfo.name}> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities);
|
||||
|
||||
/**
|
||||
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<$!{tableInfo.name}> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
|
@ -73,4 +89,4 @@ public interface $!{tableName} {
|
|||
*/
|
||||
int deleteById($!pk.shortType $!pk.name);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,24 @@ $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
|
|||
values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</insert>
|
||||
|
||||
<insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
|
||||
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
|
||||
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
#foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($velocityHasNext), #end#end
|
||||
</insert>
|
||||
|
||||
<!--通过主键修改数据-->
|
||||
<update id="update">
|
||||
update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
|
||||
|
@ -77,4 +95,4 @@ $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
|
|||
delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
##导入宏定义
|
||||
$!define
|
||||
|
||||
##设置表后缀(宏定义)
|
||||
#setTableSuffix("Controller")
|
||||
|
||||
##保存文件(宏定义)
|
||||
#save("/controller", "Controller.java")
|
||||
|
||||
##包路径(宏定义)
|
||||
#setPackageSuffix("controller")
|
||||
|
||||
##定义服务名
|
||||
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
|
||||
|
||||
##定义实体对象名
|
||||
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.api.ApiController;
|
||||
import com.baomidou.mybatisplus.extension.api.R;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
|
||||
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表控制层")
|
||||
@RestController
|
||||
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
|
||||
public class $!{tableName} extends ApiController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Resource
|
||||
private $!{tableInfo.name}Service $!{serviceName};
|
||||
|
||||
/**
|
||||
* 分页查询所有数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param $!entityName 查询实体
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping
|
||||
public R selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
|
||||
return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
public R selectOne(@PathVariable Serializable id) {
|
||||
return success(this.$!{serviceName}.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param $!entityName 实体对象
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
public R insert(@RequestBody $!tableInfo.name $!entityName) {
|
||||
return success(this.$!{serviceName}.save($!entityName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param $!entityName 实体对象
|
||||
* @return 修改结果
|
||||
*/
|
||||
@PutMapping
|
||||
public R update(@RequestBody $!tableInfo.name $!entityName) {
|
||||
return success(this.$!{serviceName}.updateById($!entityName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param idList 主键结合
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping
|
||||
public R delete(@RequestParam("idList") List<Long> idList) {
|
||||
return success(this.$!{serviceName}.removeByIds(idList));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
##导入宏定义
|
||||
$!define
|
||||
|
||||
##设置表后缀(宏定义)
|
||||
#setTableSuffix("Dao")
|
||||
|
||||
##保存文件(宏定义)
|
||||
#save("/dao", "Dao.java")
|
||||
|
||||
##包路径(宏定义)
|
||||
#setPackageSuffix("dao")
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表数据库访问层")
|
||||
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<$!{tableInfo.name}> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities);
|
||||
|
||||
/**
|
||||
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<$!{tableInfo.name}> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities);
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
##导入宏定义
|
||||
$!define
|
||||
|
||||
##保存文件(宏定义)
|
||||
#save("/entity", ".java")
|
||||
|
||||
##包路径(宏定义)
|
||||
#setPackageSuffix("entity")
|
||||
|
||||
##自动导入包(全局变量)
|
||||
$!autoImport
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import java.io.Serializable;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表实体类")
|
||||
@SuppressWarnings("serial")
|
||||
public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> {
|
||||
#foreach($column in $tableInfo.fullColumn)
|
||||
#if(${column.comment})//${column.comment}#end
|
||||
|
||||
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
|
||||
#end
|
||||
|
||||
#foreach($column in $tableInfo.fullColumn)
|
||||
#getSetMethod($column)
|
||||
#end
|
||||
|
||||
#foreach($column in $tableInfo.pkColumn)
|
||||
/**
|
||||
* 获取主键值
|
||||
*
|
||||
* @return 主键值
|
||||
*/
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.$!column.name;
|
||||
}
|
||||
#break
|
||||
#end
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
##引入mybatis支持
|
||||
$!mybatisSupport
|
||||
|
||||
##设置保存名称与保存位置
|
||||
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.xml"))
|
||||
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
|
||||
|
||||
##拿到主键
|
||||
#if(!$tableInfo.pkColumn.isEmpty())
|
||||
#set($pk = $tableInfo.pkColumn.get(0))
|
||||
#end
|
||||
|
||||
<?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="$!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao">
|
||||
|
||||
<resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
|
||||
#foreach($column in $tableInfo.fullColumn)
|
||||
<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
<!-- 批量插入 -->
|
||||
<insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
|
||||
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</foreach>
|
||||
</insert>
|
||||
<!-- 批量插入或按主键更新 -->
|
||||
<insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
|
||||
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
#foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($velocityHasNext), #end#end
|
||||
</insert>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,20 @@
|
|||
##导入宏定义
|
||||
$!define
|
||||
|
||||
##设置表后缀(宏定义)
|
||||
#setTableSuffix("Service")
|
||||
|
||||
##保存文件(宏定义)
|
||||
#save("/service", "Service.java")
|
||||
|
||||
##包路径(宏定义)
|
||||
#setPackageSuffix("service")
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表服务接口")
|
||||
public interface $!{tableName} extends IService<$!tableInfo.name> {
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
##导入宏定义
|
||||
$!define
|
||||
|
||||
##设置表后缀(宏定义)
|
||||
#setTableSuffix("ServiceImpl")
|
||||
|
||||
##保存文件(宏定义)
|
||||
#save("/service/impl", "ServiceImpl.java")
|
||||
|
||||
##包路径(宏定义)
|
||||
#setPackageSuffix("service.impl")
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;
|
||||
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
|
||||
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表服务实现类")
|
||||
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
|
||||
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}> implements $!{tableInfo.name}Service {
|
||||
|
||||
}
|
Loading…
Reference in New Issue