mirror of
https://gitee.com/ChinaLym/shoulder-platform.git
synced 2025-12-30 02:52:27 +00:00
feat(code-gen): 去掉 spring-cloud 依赖,无需注册中心,简化配置和使用
This commit is contained in:
@@ -3,10 +3,9 @@
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>cn.itlym.platform</groupId>
|
||||
<artifactId>shoulder-platform-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version><!-- shoulder-platform-version -->
|
||||
<relativePath>../../shoulder-platform-common/shoulder-platform-parent/pom.xml</relativePath>
|
||||
<groupId>cn.itlym</groupId>
|
||||
<artifactId>shoulder-parent</artifactId>
|
||||
<version>0.4</version><!-- shoulder-version -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -21,16 +20,6 @@
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.itlym.platform</groupId>
|
||||
<artifactId>shoulder-platform-starter-db</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.itlym.platform</groupId>
|
||||
<artifactId>shoulder-platform-starter-config-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
@@ -42,68 +31,44 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.itlym.platform</groupId>
|
||||
<artifactId>shoulder-platform-starter-rpc-server</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- 默认使用 mysql -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 彩色日志等,比 spring-boot-starter-web 更简便 -->
|
||||
<dependency>
|
||||
<groupId>cn.itlym</groupId>
|
||||
<artifactId>shoulder-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<!-- 生成带第三方jar包的可执行jar包 -->
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- 项目名 -->
|
||||
<!-- ${docker.image.prefix} : dockerHub 上注册的名字 -->
|
||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||
<dockerDirectory>src/main/docker</dockerDirectory>
|
||||
<!-- docker远程服务器地址 -->
|
||||
<dockerHost>${docker.host}</dockerHost>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.yml</include>
|
||||
</includes>
|
||||
<!-- 是否替换资源中的属性-->
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.*</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
</build>
|
||||
|
||||
</resources></build>
|
||||
</project>
|
||||
@@ -1,14 +1,17 @@
|
||||
package cn.itlym.shoulder.generator;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 启动类
|
||||
* 代码生成器,根据数据库表,生成 Entity、RestApi、Controller、Service、ServiceImpl、Repository、Mapper、Mapper.xml、前端视图
|
||||
*
|
||||
* @author lym
|
||||
*/
|
||||
|
||||
@MapperScan(value = "cn.itlym.shoulder.generator.mapper")
|
||||
@Configuration
|
||||
@SpringBootApplication
|
||||
public class GeneratorApp {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class GeneratorController {
|
||||
/**
|
||||
* 生成代码
|
||||
* web 中不需要主动关闭流
|
||||
* http://localhost:8080/generator/code?tables=*
|
||||
* <a href="http://localhost:8080/generator/code?tables=_all">所有表</a>
|
||||
*/
|
||||
@RequestMapping("/code")
|
||||
public void code(String tables, HttpServletResponse response) throws IOException {
|
||||
@@ -52,22 +52,18 @@ public class GeneratorController {
|
||||
throw new IllegalArgumentException("tableName can't be empty");
|
||||
}
|
||||
response.reset();
|
||||
byte[] data = "*".equals(tables) ? sysGeneratorService.generatorCode(response.getOutputStream()) :sysGeneratorService.generatorCode(tables.split(","), response.getOutputStream());
|
||||
if (data != null && data.length > 0) {
|
||||
/*
|
||||
// file out put stream 必须及时关闭
|
||||
OutputStream out = new FileOutputStream("F:/te.zip");
|
||||
IOUtils.write(data, out);
|
||||
IOUtils.closeQuietly(out);
|
||||
*/
|
||||
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"generator.zip\"");
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
response.addHeader("Content-Length", String.valueOf(data.length));
|
||||
|
||||
// response out put stream 会自动关闭
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
byte[] data = "_all".equals(tables) ? sysGeneratorService.generatorCode(response.getOutputStream())
|
||||
:sysGeneratorService.generatorCode(tables.split(","), response.getOutputStream());
|
||||
if (data == null || data.length == 0) {
|
||||
return;
|
||||
}
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"generator.zip\"");
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
// ClientAbortException: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。加上这行有下载进度,不加可能报错
|
||||
response.addHeader("Content-Length", String.valueOf(data.length));
|
||||
|
||||
// response out put stream 会自动关闭
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.itlym.shoulder.generator.dao;
|
||||
package cn.itlym.shoulder.generator.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface SysGeneratorDao {
|
||||
public interface SysGeneratorMapper {
|
||||
|
||||
List<Map<String, Object>> queryList(Map<String, Object> map);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?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="cn.itlym.shoulder.generator.dao.SysGeneratorDao">
|
||||
<mapper namespace="cn.itlym.shoulder.generator.mapper.SysGeneratorMapper">
|
||||
<select id="queryList" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from
|
||||
information_schema.tables
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.itlym.shoulder.generator.service.impl;
|
||||
|
||||
import cn.itlym.shoulder.generator.dao.SysGeneratorDao;
|
||||
import cn.itlym.shoulder.generator.mapper.SysGeneratorMapper;
|
||||
import cn.itlym.shoulder.generator.service.SysGeneratorService;
|
||||
import cn.itlym.shoulder.generator.utils.GenUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -27,14 +27,14 @@ import java.util.zip.ZipOutputStream;
|
||||
public class SysGeneratorServiceImpl implements SysGeneratorService {
|
||||
|
||||
@Autowired
|
||||
private SysGeneratorDao sysGeneratorDao;
|
||||
private SysGeneratorMapper sysGeneratorMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public PageResult queryList(Map<String, Object> map) {
|
||||
//设置分页信息,分别是当前页数和每页显示的总记录数【记住:必须在mapper接口中的方法执行之前设置该分页信息】
|
||||
PageHelper.startPage(MapUtils.getInteger(map, "page"), MapUtils.getInteger(map, "limit"), true);
|
||||
List<Map<String, Object>> list = sysGeneratorDao.queryList(map);
|
||||
List<Map<String, Object>> list = sysGeneratorMapper.queryList(map);
|
||||
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
|
||||
|
||||
return PageResult.PageInfoConverter.toResult(pageInfo);
|
||||
@@ -47,12 +47,12 @@ public class SysGeneratorServiceImpl implements SysGeneratorService {
|
||||
|
||||
@Override
|
||||
public Map<String, String> queryTable(String tableName) {
|
||||
return sysGeneratorDao.queryTable(tableName);
|
||||
return sysGeneratorMapper.queryTable(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> queryColumns(String tableName) {
|
||||
return sysGeneratorDao.queryColumns(tableName);
|
||||
return sysGeneratorMapper.queryColumns(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +81,7 @@ public class SysGeneratorServiceImpl implements SysGeneratorService {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
// 查询所有表信息
|
||||
List<Map<String, String>> tables = sysGeneratorDao.listTable();
|
||||
List<Map<String, String>> tables = sysGeneratorMapper.listTable();
|
||||
for (Map<String, String> table : tables) {
|
||||
String tableName = table.get("TABLE_NAME");
|
||||
//查询列信息
|
||||
|
||||
10
shoulder-generator/src/main/resources/application.yml
Normal file
10
shoulder-generator/src/main/resources/application.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
spring:
|
||||
application:
|
||||
name: shoulder-generator
|
||||
|
||||
datasource:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
# 改成你要生成的数据库地址
|
||||
username: root
|
||||
password: root
|
||||
url: jdbc:mysql://127.0.0.1:3306/shoulder_platform?serverTimezone=CTT&characterEncoding=utf8&useUnicode=true&useSSL=false&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&allowPublicKeyRetrieval=true
|
||||
@@ -1,15 +0,0 @@
|
||||
spring:
|
||||
#allow-bean-definition-overriding: true
|
||||
application:
|
||||
name: generator
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: itlym.cn:8848
|
||||
file-extension: yml
|
||||
shared-configs:
|
||||
- dataId: common.yml
|
||||
refresh: true
|
||||
- dataId: db.yml
|
||||
refresh: true
|
||||
enabled: true
|
||||
@@ -17,7 +17,6 @@ import java.util.Date;
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package ${package}.${pkgName}.repository;
|
||||
|
||||
import ${package}.${pkgName}.entity.${className};
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.OmsLockDO;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -10,6 +9,7 @@ import javax.transaction.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${comments}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user