实现用户角色权限区域管理模块
This commit is contained in:
42
guigu-ssyx-parent/common/common-util/pom.xml
Normal file
42
guigu-ssyx-parent/common/common-util/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common-util</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@@ -0,0 +1,32 @@
|
||||
package com.atguigu.ssyx.common.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
||||
public final class MD5 {
|
||||
|
||||
public static String encrypt(String strSrc) {
|
||||
try {
|
||||
char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
byte[] bytes = strSrc.getBytes();
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(bytes);
|
||||
bytes = md.digest();
|
||||
int j = bytes.length;
|
||||
char[] chars = new char[j * 2];
|
||||
int k = 0;
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
byte b = bytes[i];
|
||||
chars[k++] = hexChars[b >>> 4 & 0xf];
|
||||
chars[k++] = hexChars[b & 0xf];
|
||||
}
|
||||
return new String(chars);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("MD5加密出错!!+" + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
59
guigu-ssyx-parent/common/pom.xml
Normal file
59
guigu-ssyx-parent/common/pom.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>guigu-ssyx-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>common-util</module>
|
||||
<module>service-util</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--lombok用来简化实体类:需要安装lombok插件-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- https://doc.xiaominfo.com/knife4j/documentation/ -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--用来转换json使用 {JavaObject - json | json - JavaObject}-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 服务调用feign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
75
guigu-ssyx-parent/common/service-util/pom.xml
Normal file
75
guigu-ssyx-parent/common/service-util/pom.xml
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service-util</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-util</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- spring2.X集成redis所需common-pool2-->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>2.6.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- redisson 分布式锁-->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.11.2</version>
|
||||
</dependency>
|
||||
|
||||
<!--mybatis-plus-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- 代码生成器-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@@ -0,0 +1,34 @@
|
||||
package com.atguigu.ssyx.common.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* ClassName: MyBatisPlusConfig
|
||||
* Package: com.atguigu.ssyx.common.config
|
||||
* MybatisPlus配置类
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 12:56
|
||||
*/
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
@MapperScan("com.atguigu.ssyx.*.mapper")
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* mp插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor optimisticLockerInnerInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
//向Mybatis过滤器链中添加分页拦截器
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
package com.atguigu.ssyx.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.ParameterBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.service.Parameter;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: Swagger2Config
|
||||
* Package: com.atguigu.ssyx.common.config
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 13:18
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2WebMvc
|
||||
public class Swagger2Config {
|
||||
|
||||
@Bean
|
||||
public Docket webApiConfig() {
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
tokenPar
|
||||
.name("userId")
|
||||
.description("用户token")
|
||||
//.defaultValue(JwtHelper.createToken(1L, "admin"))
|
||||
.defaultValue("1")
|
||||
.modelRef(new ModelRef("string"))
|
||||
.parameterType("header")
|
||||
.required(false)
|
||||
.build();
|
||||
pars.add(tokenPar.build());
|
||||
|
||||
Docket webApi = new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("webApi")
|
||||
.apiInfo(webApiInfo())
|
||||
.select()
|
||||
//只显示api路径下的页面
|
||||
.apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx"))
|
||||
.paths(PathSelectors.regex("/api/.*"))
|
||||
.build()
|
||||
.globalOperationParameters(pars);
|
||||
return webApi;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket adminApiConfig() {
|
||||
List<Parameter> pars = new ArrayList<>();
|
||||
ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
tokenPar
|
||||
.name("adminId")
|
||||
.description("用户token")
|
||||
.defaultValue("1")
|
||||
.modelRef(new ModelRef("string"))
|
||||
.parameterType("header")
|
||||
.required(false)
|
||||
.build();
|
||||
pars.add(tokenPar.build());
|
||||
|
||||
Docket adminApi = new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("adminApi")
|
||||
.apiInfo(adminApiInfo())
|
||||
.select()
|
||||
//只显示admin路径下的页面
|
||||
.apis(RequestHandlerSelectors.basePackage("com.atguigu.ssyx"))
|
||||
.paths(PathSelectors.regex("/admin/.*"))
|
||||
.build()
|
||||
.globalOperationParameters(pars);
|
||||
return adminApi;
|
||||
}
|
||||
|
||||
private ApiInfo webApiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("网站-API文档")
|
||||
.description("本文档描述了尚上优选网站微服务接口定义")
|
||||
.version("1.0")
|
||||
.contact(new Contact("atguigu", "http://atguigu.com", "atguigu"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo adminApiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("后台管理系统-API文档")
|
||||
.description("本文档描述了尚上优选后台系统服务接口定义")
|
||||
.version("1.0")
|
||||
.contact(new Contact("atguigu", "http://atguigu.com", "atguigu"))
|
||||
.build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.atguigu.ssyx.common.exception;
|
||||
|
||||
import com.atguigu.ssyx.common.result.Result;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* ClassName: GlobalExceptionHandler
|
||||
* Package: com.atguigu.ssyx.common.exception
|
||||
* 统一异常处理类
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 13:03
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Result error(Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.fail(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义异常处理方法
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(SsyxException.class)
|
||||
@ResponseBody
|
||||
public Result error(SsyxException e) {
|
||||
return Result.build(null, e.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package com.atguigu.ssyx.common.exception;
|
||||
|
||||
import com.atguigu.ssyx.common.result.ResultCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* ClassName: SsyxException
|
||||
* Package: com.atguigu.ssyx.common.exception
|
||||
* 自定义异常类
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 13:05
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class SsyxException extends RuntimeException {
|
||||
|
||||
//异常状态码
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 通过状态码和错误消息创建异常对象
|
||||
*
|
||||
* @param message
|
||||
* @param code
|
||||
*/
|
||||
public SsyxException(String message, Integer code) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收枚举类型对象
|
||||
*
|
||||
* @param resultCodeEnum
|
||||
*/
|
||||
public SsyxException(ResultCodeEnum resultCodeEnum) {
|
||||
super(resultCodeEnum.getMessage());
|
||||
this.code = resultCodeEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GuliException{" + "code=" + code + ", message=" + this.getMessage() + '}';
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
package com.atguigu.ssyx.common.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* ClassName: Result
|
||||
* Package: com.atguigu.ssyx.common.result
|
||||
* 统一返回结果类
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 13:01
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> {
|
||||
|
||||
//状态码
|
||||
private Integer code;
|
||||
//信息
|
||||
private String message;
|
||||
//数据
|
||||
private T data;
|
||||
|
||||
//构造私有化
|
||||
private Result() {
|
||||
}
|
||||
|
||||
//设置数据,返回对象的方法
|
||||
public static <T> Result<T> build(T data, Integer code, String message) {
|
||||
//创建Result对象,设置值,返回对象
|
||||
Result<T> result = new Result<>();
|
||||
//判断返回结果中是否需要数据
|
||||
if (data != null) {
|
||||
//设置数据到result对象
|
||||
result.setData(data);
|
||||
}
|
||||
//设置其他值
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
//返回设置值之后的对象
|
||||
return result;
|
||||
}
|
||||
|
||||
//设置数据,返回对象的方法
|
||||
public static <T> Result<T> build(T data, ResultCodeEnum resultCodeEnum) {
|
||||
//创建Result对象,设置值,返回对象
|
||||
Result<T> result = new Result<>();
|
||||
//判断返回结果中是否需要数据
|
||||
if (data != null) {
|
||||
//设置数据到result对象
|
||||
result.setData(data);
|
||||
}
|
||||
//设置其他值
|
||||
result.setCode(resultCodeEnum.getCode());
|
||||
result.setMessage(resultCodeEnum.getMessage());
|
||||
//返回设置值之后的对象
|
||||
return result;
|
||||
}
|
||||
|
||||
//成功的方法
|
||||
public static <T> Result<T> ok(T data) {
|
||||
return build(data, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
//失败的方法
|
||||
public static <T> Result<T> fail(T data) {
|
||||
return build(data, ResultCodeEnum.FAIL);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.atguigu.ssyx.common.result;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ClassName: ResultCodeEnum
|
||||
* Package: com.atguigu.ssyx.common.result
|
||||
* 统一返回结果状态信息类
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/13 12:59
|
||||
*/
|
||||
@Getter
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
SUCCESS(200, "成功"), FAIL(201, "失败"), SERVICE_ERROR(2012, "服务异常"), DATA_ERROR(204, "数据异常"), ILLEGAL_REQUEST(205, "非法请求"), REPEAT_SUBMIT(206, "重复提交"),
|
||||
|
||||
LOGIN_AUTH(208, "未登陆"), PERMISSION(209, "没有权限"),
|
||||
|
||||
ORDER_PRICE_ERROR(210, "订单商品价格变化"), ORDER_STOCK_FALL(204, "订单库存锁定失败"), CREATE_ORDER_FAIL(210, "创建订单失败"),
|
||||
|
||||
COUPON_GET(220, "优惠券已经领取"), COUPON_LIMIT_GET(221, "优惠券已发放完毕"),
|
||||
|
||||
URL_ENCODE_ERROR(216, "URL编码失败"), ILLEGAL_CALLBACK_REQUEST_ERROR(217, "非法回调请求"), FETCH_ACCESSTOKEN_FAILD(218, "获取accessToken失败"), FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
||||
|
||||
|
||||
SKU_LIMIT_ERROR(230, "购买个数不能大于限购个数"), REGION_OPEN(240, "该区域已开通"), REGION_NO_OPEN(240, "该区域未开通"),
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
|
||||
private final String message;
|
||||
|
||||
ResultCodeEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package com.atguigu.ssyx;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
/**
|
||||
* ClassName: CodeGet
|
||||
* Package: com.atguigu.ssyx
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/14 08:49
|
||||
*/
|
||||
public class CodeGet {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 1、创建代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 2、全局配置
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
gc.setOutputDir("guigu-ssyx-parent/service/service-sys" + "/src/main/java");
|
||||
|
||||
gc.setServiceName("%sService"); //去掉Service接口的首字母I
|
||||
gc.setAuthor("atguigu");
|
||||
gc.setOpen(false);
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 3、数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://82.157.68.223:3306/shequ-sys?serverTimezone=GMT%2B8&useSSL=false");
|
||||
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
dsc.setUsername("shequ-sys");
|
||||
dsc.setPassword("shequ-sys");
|
||||
dsc.setDbType(DbType.MYSQL);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 4、包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setParent("com.atguigu.ssyx");
|
||||
pc.setModuleName("sys"); //模块名
|
||||
pc.setController("controller");
|
||||
pc.setService("service");
|
||||
pc.setMapper("mapper");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 5、策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
|
||||
strategy.setInclude("region", "ware", "region_ware");
|
||||
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
|
||||
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
|
||||
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
|
||||
strategy.setRestControllerStyle(true); //restful api风格控制器
|
||||
strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
|
||||
|
||||
mpg.setStrategy(strategy);
|
||||
|
||||
// 6、执行
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user