Commit 91333ecd authored by shangtx's avatar shangtx

chore: 代码生成器搬运

parent 82d7e46b
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
<module>common</module> <module>common</module>
<module>admin</module> <module>admin</module>
<module>mini-app</module> <module>mini-app</module>
<module>test</module>
</modules> </modules>
<dependencies> <dependencies>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>com.onsiteservice</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test</artifactId>
<dependencies>
<!--依赖公共通用模块-->
<dependency>
<groupId>com.onsiteservice</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</dependency>
<!--代码生成器依赖-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
package com.onsiteservice;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;
import java.sql.Types;
/**
* @author 潘维吉
* @date 2020-02-05 9:10
* 自定义Mybatis自动生成代码数据类型转换
*/
public class MyJavaTypeResolverImpl extends JavaTypeResolverDefaultImpl {
public MyJavaTypeResolverImpl() {
super();
//把数据库的 TINYINT 映射成 Integer 类型 而不是Byte类型 简化程序开发
super.typeMap.put(Types.TINYINT, new JdbcTypeInformation("TINYINT", new FullyQualifiedJavaType(Integer.class.getName())));
super.typeMap.put(Types.SMALLINT, new JdbcTypeInformation("SMALLINT", new FullyQualifiedJavaType(Integer.class.getName())));
}
}
<#if isGenFileModule >
package ${currentPackage}.controller.${fileModule};
import ${entityPackage}.${fileModule}.${modelNameUpperCamel};
import ${currentPackage}.service.${fileModule}.${modelNameUpperCamel}Service;
<#else>
package ${currentPackage}.controller;
import ${entityPackage}.${modelNameUpperCamel};
import ${currentPackage}.service.${modelNameUpperCamel}Service;
</#if>
import ${corePackage}.result.Result;
import ${commonDaoPackage}.common.page.PageParams;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.Positive;
import static ${corePackage}.result.ResultGenerator.success;
import static ${corePackage}.result.ResultGenerator.fail;
/**
* @author ${author}
* @date ${date}
* @description ${modelNameUpperCamel}Controller控制类
*/
@RestController
@RequestMapping("${requestMappingPath}")
@Validated
public class ${modelNameUpperCamel}Controller {
@Resource
private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;
/**
* 分页查询列表
*
* @param param 分页参数
* @return 分页数据
*/
@PostMapping("/page")
public Result getPage(@RequestBody @NonNull @Validated PageParams param) {
return success(${modelNameLowerCamel}Service.getPage(param), "获取分页列表");
}
/**
* 根据id查询
*
* @param id 主键
* @return 详情数据
*/
@GetMapping("/{id}")
public Result getDetails(@PathVariable @Positive Long id) {
return success(${modelNameLowerCamel}Service.selectByPrimaryKey(id), "根据id获取详情");
}
<#if isGenSaveOrUpdate >
/**
* 新增或修改
*/
@PostMapping("/save-or-update")
public Result saveOrUpdate(@RequestBody @NonNull @Validated ${modelNameUpperCamel} ${modelNameLowerCamel}) {
return success(${modelNameLowerCamel}Service.saveOrUpdate(${modelNameLowerCamel}), ${modelNameLowerCamel}.getId() == null ? "新增成功" : "修改成功");
}
<#else>
/**
* 新增
*
* @param ${modelNameLowerCamel} 新增对象
*/
@PostMapping
public Result save(@RequestBody @NonNull @Validated ${modelNameUpperCamel} ${modelNameLowerCamel}) {
return success(${modelNameLowerCamel}Service.insertSelective(${modelNameLowerCamel}), "新增成功");
}
/**
* 修改
*
* @param ${modelNameLowerCamel} 修改对象
*/
@PutMapping
public Result update(@RequestBody @NonNull @Validated ${modelNameUpperCamel} ${modelNameLowerCamel}) {
return success(${modelNameLowerCamel}Service.updateByPrimaryKeySelective(${modelNameLowerCamel}), "修改成功");
}
</#if>
/**
* 根据id删除
*
* @param id 主键
*/
@DeleteMapping("/{id}")
public Result deleteById(@PathVariable @Positive Long id) {
return success(${modelNameLowerCamel}Service.deleteByPrimaryKey(id), "删除成功");
}
}
<#if isGenFileModule >
package ${currentPackage}.controller.${fileModule};
import ${entityPackage}.${fileModule}.${modelNameUpperCamel};
import ${currentPackage}.service.${fileModule}.${modelNameUpperCamel}Service;
<#else>
package ${currentPackage}.controller;
import ${daoPackage}.model.${modelNameUpperCamel};
import ${currentPackage}.service.${modelNameUpperCamel}Service;
</#if>
import ${corePackage}.result.Result;
import ${commonDaoPackage}.common.page.PageInfoVO;
import ${commonDaoPackage}.common.page.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import javax.validation.constraints.Positive;
import static ${corePackage}.result.ResultGenerator.success;
import static ${corePackage}.result.ResultGenerator.fail;
/**
* @author ${author}
* @date ${date}
* @description ${modelNameUpperCamel}Controller控制类
*/
@ApiIgnore
@Api(tags = "${modelNameUpperCamel}Controller")
@RestController
@RequestMapping("${requestMappingPath}")
@Validated
public class ${modelNameUpperCamel}Controller {
@Resource
private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;
@ApiOperation(value = "分页查询列表", notes = "作者: ${author}")
@PostMapping("/page")
public Result<PageInfoVO> getPage(@RequestBody @NonNull @Validated PageParams param) {
return success(${modelNameLowerCamel}Service.getPage(param), "获取分页列表");
}
@ApiOperation(value = "根据id查询", notes = "作者: ${author}")
@GetMapping("/{id}")
public Result<${modelNameUpperCamel}> getDetails(@PathVariable @Positive Long id) {
return success(${modelNameLowerCamel}Service.selectByPrimaryKey(id), "根据id获取详情");
}
<#if isGenSaveOrUpdate >
@ApiOperation(value = "新增或修改", notes = "作者: ${author}")
@PostMapping("/save-or-update")
public Result saveOrUpdate(@RequestBody @NonNull @Validated ${modelNameUpperCamel} ${modelNameLowerCamel}) {
return success(${modelNameLowerCamel}Service.saveOrUpdate(${modelNameLowerCamel}), ${modelNameLowerCamel}.getId() == null ? "新增成功" : "修改成功");
}
<#else>
@ApiOperation(value = "新增", notes = "作者: ${author}")
@PostMapping
public Result save(@RequestBody @NonNull @Validated ${modelNameUpperCamel} ${modelNameLowerCamel}) {
return success(${modelNameLowerCamel}Service.insertSelective(${modelNameLowerCamel}), "新增成功");
}
@ApiOperation(value = "修改", notes = "作者: ${author}")
@PutMapping
public Result update(@RequestBody @NonNull @Validated ${modelNameUpperCamel} ${modelNameLowerCamel}) {
return success(${modelNameLowerCamel}Service.updateByPrimaryKeySelective(${modelNameLowerCamel}), "修改成功");
}
</#if>
@ApiOperation(value = "根据id删除", notes = "作者: ${author}")
@DeleteMapping("/{id}")
public Result deleteById(@PathVariable @Positive Long id) {
return success(${modelNameLowerCamel}Service.deleteByPrimaryKey(id), "删除成功");
}
}
<?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">
<#if isGenFileModule >
<mapper namespace="${currentPackage}.mapper.${fileModule}.${modelNameUpperCamel}BizMapper">
<#else>
<mapper namespace="${currentPackage}.mapper.${modelNameUpperCamel}BizMapper">
</#if>
<#if isGenPage >
<!--分页查询列表-->
<select id="getPage" resultType="map">
select t1.*
from t1
<where>
and t1.is_deleted = 0
<if test="param.name != null and param.name != ''">
and t1.name like <#noparse>"%"#{param.name}"%"</#noparse>
</if>
</where>
order by
<if test="param.sort != null and param.sort != ''">
<#noparse>${param.sort} ${param.order}</#noparse>,
</if>
t1.id desc
</select>
</#if>
</mapper>
<#if isGenFileModule >
package ${currentPackage}.mapper.${fileModule};
<#else>
package ${currentPackage}.mapper;
</#if>
<#if isGenPage >
import ${commonDaoPackage}.common.page.PageParams;
import org.apache.ibatis.annotations.Param;
import java.util.List;
</#if>
/**
* @author ${author}
* @date ${date}
* @description ${modelNameUpperCamel}BizMapper业务接口
*/
public interface ${modelNameUpperCamel}BizMapper {
<#if isGenPage >
/**
* 分页查询列表
*/
List getPage(@Param("param") PageParams param);
</#if>
}
<#if isGenFileModule >
package ${currentPackage}.service.${fileModule};
import ${entityPackage}.${fileModule}.${modelNameUpperCamel};
<#if isGenMapperSeparate >
import ${daoPackage}.mapper.${fileModule}.${modelNameUpperCamel}Mapper;
import ${currentPackage}.mapper.${fileModule}.${modelNameUpperCamel}BizMapper;
<#else>
import ${currentPackage}.mapper.${fileModule}.${modelNameUpperCamel}Mapper;
</#if>
<#else>
package ${currentPackage}.service;
import ${entityPackage}.${modelNameUpperCamel};
<#if isGenMapperSeparate >
import ${daoPackage}.mapper.${modelNameUpperCamel}Mapper;
import ${currentPackage}.mapper.${modelNameUpperCamel}BizMapper;
<#else>
import ${currentPackage}.mapper.${modelNameUpperCamel}Mapper;
</#if>
</#if>
import ${commonDaoPackage}.common.AbstractMapper;
import ${commonDaoPackage}.common.page.PageParams;
import ${commonDaoPackage}.common.page.PageInfoVO;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* @author ${author}
* @date ${date}
* @description ${modelNameUpperCamel}Service服务类
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ${modelNameUpperCamel}Service extends AbstractMapper<${modelNameUpperCamel}> {
@Resource
private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;
<#if isGenMapperSeparate >
@Resource
private ${modelNameUpperCamel}BizMapper ${modelNameLowerCamel}BizMapper;
</#if>
/**
* 分页查询列表
*/
public PageInfoVO getPage(PageParams param) {
PageHelper.startPage(param.getPage(), param.getSize());
<#if !isGenPage >
return new PageInfoVO(this.selectAll());
<#else>
return new PageInfoVO(${modelNameLowerCamel}BizMapper.getPage(param));
</#if>
}
<#if isGenSaveOrUpdate >
/**
* 保存或更新方法
*/
public int saveOrUpdate(${modelNameUpperCamel} ${modelNameLowerCamel}) {
if (${modelNameLowerCamel}.getId() == null) {
return this.insertSelective(${modelNameLowerCamel});
} else {
return this.updateByPrimaryKeySelective(${modelNameLowerCamel});
}
}
</#if>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment