初始化
commit
d76eb3c8f1
|
@ -0,0 +1,44 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/misc.xml
|
||||
.idea/libraries/
|
||||
.idea/misc.xml/
|
||||
.idea/vcs.xml/
|
||||
.idea/uiDesigner.xml/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
.idea/dataSources.xml
|
||||
.idea/mybatisx/templates.xml
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,44 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/misc.xml
|
||||
.idea/libraries/
|
||||
.idea/misc.xml/
|
||||
.idea/vcs.xml/
|
||||
.idea/uiDesigner.xml/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
.idea/dataSources.xml
|
||||
.idea/mybatisx/templates.xml
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,127 @@
|
|||
<?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.hydrogen</groupId>
|
||||
<artifactId>hydrogen</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.hydrogen</groupId>
|
||||
<artifactId>hydrogen-applet</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>hydrogen-applet</name>
|
||||
<description>吸氢机小程序</description>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- alibaba dataSource -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis-Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis-Plus 自动代码生成器 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring-cloud-alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hydrogen</groupId>
|
||||
<artifactId>hydrogen-mbg</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>Nexus Repository</name>
|
||||
<url>http://nexus.derunht.cn/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<!-- 私服仓库配置:从私服下载-->
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>nexus</id>
|
||||
<name>Nexus Plugin Repository</name>
|
||||
<url>http://nexus.derunht.cn/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>1.4.2.RELEASE</version>
|
||||
<configuration>
|
||||
<!-- ⭐设定启动类-->
|
||||
<mainClass>com.hydrogen.examSystem.ExamSystemApplication</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
package com.hydrogen;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@MapperScan(basePackages ="com.hydrogen.applet.dao")
|
||||
@EnableAsync
|
||||
@SpringBootApplication
|
||||
public class HydrogenAppletApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HydrogenAppletApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.hydrogen;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(HydrogenAppletApplication.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.hydrogen.applet.config;
|
||||
|
||||
import feign.Logger;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Feign 客户端日志配置
|
||||
*/
|
||||
@Configuration
|
||||
public class FeignConfiguration {
|
||||
|
||||
@Bean
|
||||
Logger.Level feignLevel() {
|
||||
return Logger.Level.BASIC;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.hydrogen.applet.config;
|
||||
|
||||
import feign.Feign;
|
||||
import okhttp3.ConnectionPool;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName OpenFeignInterfaceConfiguration
|
||||
* @Description OpenFeignConfig 配置管理
|
||||
* @Author chaixueteng
|
||||
* @Date 2020/3/10 9:46
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(Feign.class)
|
||||
@AutoConfigureBefore(FeignAutoConfiguration.class)
|
||||
public class FeignOkHttpConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public okhttp3.OkHttpClient okHttpClient(){
|
||||
return new okhttp3.OkHttpClient.Builder()
|
||||
//设置连接超时
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
//设置读超时
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
//是否自动重连
|
||||
.retryOnConnectionFailure(true)
|
||||
// 最大连接数、连接存活时间、存活时间单位(分钟)
|
||||
.connectionPool(new ConnectionPool(200, 5, TimeUnit.MINUTES))
|
||||
//构建OkHttpClient对象
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.hydrogen.applet.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.hydrogen.examSystem.dao")
|
||||
public class MyBatisPlusConfig {
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
|
||||
// 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
|
||||
return interceptor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
package com.hydrogen.applet.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @ClassName MybatisGenerator
|
||||
* @Description mybatis生成器
|
||||
* @Author chaixueteng
|
||||
* @Date 2020/3/11 10:34
|
||||
*/
|
||||
public class MybatisGenerator {
|
||||
|
||||
private static final String MYSQL_URL ="jdbc:mysql://120.46.194.248:13306/jhqm_exam?useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true";
|
||||
private static final String MYSQL_DRIVE ="com.mysql.cj.jdbc.Driver";
|
||||
private static final String MYSQL_U ="exam_user";
|
||||
private static final String MYSQL_P ="7Js$A2LcTKy=";
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 读取控制台内容
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public static String scanner(String tip) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
StringBuilder help = new StringBuilder();
|
||||
help.append("请输入" + tip + ":");
|
||||
System.out.println(help.toString());
|
||||
if (scanner.hasNext()) {
|
||||
String ipt = scanner.next();
|
||||
if (StringUtils.isNotEmpty(ipt)) {
|
||||
return ipt;
|
||||
}
|
||||
}
|
||||
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
final String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/src/main/java");
|
||||
gc.setAuthor("linyx");
|
||||
gc.setOpen(false);
|
||||
gc.setServiceName("%sService");// service 命名方式
|
||||
gc.setServiceImplName("%sServiceImpl");// service impl 命名方式
|
||||
// 自定义文件命名,注意 %s 会自动填充表实体属性!
|
||||
gc.setMapperName("%sDao");
|
||||
gc.setXmlName("%sDao");
|
||||
gc.setFileOverride(true);
|
||||
gc.setActiveRecord(true);
|
||||
gc.setEnableCache(false);// XML 二级缓存
|
||||
gc.setBaseResultMap(true);// XML ResultMap
|
||||
gc.setBaseColumnList(true);// XML columList
|
||||
gc.setIdType(IdType.ASSIGN_ID);
|
||||
gc.setSwagger2(true);
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(MYSQL_URL);
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName(MYSQL_DRIVE);
|
||||
dsc.setUsername(MYSQL_U);
|
||||
dsc.setPassword(MYSQL_P);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
//pc.setModuleName(scanner("模块名"));
|
||||
pc.setParent("com.hydrogen.examSystem");
|
||||
pc.setEntity("entity");
|
||||
pc.setService("service");
|
||||
pc.setServiceImpl("service.impl");
|
||||
pc.setController("controller");// 设置控制器包名
|
||||
pc.setMapper("dao");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {}
|
||||
};
|
||||
|
||||
// 如果模板引擎是 freemarker
|
||||
String templatePath = "/templates/mapper.xml.ftl";
|
||||
|
||||
// 自定义输出配置
|
||||
List<FileOutConfig> focList = new ArrayList();
|
||||
// 自定义配置会被优先输出
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
// 自定义输出文件名
|
||||
return projectPath + "/src/main/resources/mapping/"
|
||||
+ tableInfo.getEntityName() + "Dao" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
// 配置模板
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
|
||||
templateConfig.setXml(null);
|
||||
mpg.setTemplate(templateConfig);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
//生成时 添加字段注解,解决数据库字段与实体类不一致问题 比如 mysql :f_id pojo:id
|
||||
strategy.setEntityTableFieldAnnotationEnable(true);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setRestControllerStyle(true);
|
||||
strategy.setInclude(scanner("表名"));
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setTablePrefix("t_exam_system_");
|
||||
strategy.setFieldPrefix("f_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.hydrogen.applet.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
@Configuration
|
||||
@EnableOpenApi
|
||||
@EnableKnife4j
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
Docket docket(){
|
||||
// 设置 swagger的版本
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
// 选择生成接口文档
|
||||
.select()
|
||||
// 包所在的路径
|
||||
.apis(RequestHandlerSelectors.basePackage("com.hydrogen.applet.controller"))
|
||||
// 当前包下所有接口都生成
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
// 接口文档初始化,也就是设置接口文档的详细信息,
|
||||
.apiInfo(
|
||||
new ApiInfoBuilder()
|
||||
.description("吸氢机小程序接口文档")
|
||||
.version("v1.0")
|
||||
.title("API 测试文档")
|
||||
.license("Apache 2.0")
|
||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.hydrogen.applet.filter;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hydrogen.mbg.utils.JwtTokenUtil;
|
||||
import com.hydrogen.mbg.utils.RedisUtil;
|
||||
import com.hydrogen.mbg.vo.DrhtResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* @author fjc
|
||||
* @date 2023-10-16 17:30
|
||||
*/
|
||||
@Configuration
|
||||
public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
JwtTokenUtil jwtTokenUtil;
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 请求前置校验
|
||||
*
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
* @param handler chosen handler to execute, for type and/or instance evaluation
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if ("OPTIONS".equals(request.getMethod())) {//这里通过判断请求的方法,判断此次是否是预检请求,如果是,标示,允许跨域;预检后,正式请求,这个方法参数就是我们设置的post了
|
||||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, OPTIONS, DELETE");//当判定为预检请求后,设定允许请求的方法
|
||||
response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-requested-with, Token"); //当判定为预检请求后,设定允许请求的头部类型
|
||||
response.addHeader("Access-Control-Max-Age", "1");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 从 http 请求头中取出 token
|
||||
String authorizationToken = request.getHeader("Authorization");
|
||||
if (!StringUtils.isEmpty(authorizationToken)) {
|
||||
//判断token是否有效
|
||||
return jwtTokenUtil.validateToken(authorizationToken);
|
||||
}
|
||||
|
||||
writeResponse(response);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
// String token = request.getHeader("token");
|
||||
// userDao.refreshToken(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入响应
|
||||
*
|
||||
* @param resp 响应结果
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeResponse(HttpServletResponse resp) throws IOException {
|
||||
DrhtResult<Object> fail = DrhtResult.build(1000, "请重新登陆");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
resp.setContentType("text/javascript");
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.write(JSONObject.toJSON(fail).toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.hydrogen.applet.filter;
|
||||
|
||||
import com.hydrogen.mbg.vo.DrhtResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 全局Controller参数校验异常处理
|
||||
*
|
||||
* @author linyx
|
||||
* @Date 2019/7/16
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalParameterValidationHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseBody
|
||||
public DrhtResult exception(MethodArgumentNotValidException e, HttpServletRequest request) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
BindingResult bindingResult = e.getBindingResult();
|
||||
log.error("请求[ {} ] {} 的参数校验发生错误", request.getMethod(), request.getRequestURL());
|
||||
for (ObjectError objectError : bindingResult.getAllErrors()) {
|
||||
FieldError fieldError = (FieldError) objectError;
|
||||
log.error("参数 {} = {} 校验错误:{}", fieldError.getField(), fieldError.getRejectedValue(), fieldError.getDefaultMessage());
|
||||
result.append(fieldError.getDefaultMessage());
|
||||
result.append(";");
|
||||
}
|
||||
return DrhtResult.build(400, result.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.hydrogen.applet.filter;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author fjc
|
||||
* @date 2023-10-16 17:30
|
||||
*/
|
||||
@Configuration
|
||||
public class InteceptorChainConfigFilter implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public HandlerInterceptor myIPInterceptor(){
|
||||
return new AuthenticationInterceptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(myIPInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/applet/login")
|
||||
.excludePathPatterns("/doc.html")
|
||||
.excludePathPatterns("/swagger-resources")
|
||||
.excludePathPatterns("/v2/api-docs")
|
||||
.excludePathPatterns("/v3/api-docs")
|
||||
.excludePathPatterns("/favicon.ico")
|
||||
.excludePathPatterns("/webjars/**")
|
||||
.excludePathPatterns("/upload/**");
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置跨域
|
||||
* */
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("*");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置默认资源请求路径
|
||||
* */
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动包
|
||||
url: jdbc:mysql://120.46.194.248:13306/hydrogen?useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true # 数据库名称
|
||||
username: hydrogen_user
|
||||
password: 'sFgo)_%h4CD5'
|
||||
druid:
|
||||
# 初始化大小,最小,最大
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
max-wait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties:
|
||||
druid.stat.slowSqlMillis=5000
|
||||
druid.stat.mergeSql=true;
|
||||
# 合并多个DruidDataSource的监控数据
|
||||
use-global-data-source-stat: true
|
||||
filters: stat,wall
|
||||
|
||||
redis:
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 200
|
||||
max-idle: 10
|
||||
min-idle: -1
|
||||
host: 120.46.171.171
|
||||
port: 6379
|
||||
password: bcd4@g2wp*PZv#&U
|
||||
timeout: 1000
|
||||
database: 1
|
|
@ -0,0 +1,43 @@
|
|||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动包
|
||||
url: jdbc:mysql://hydrogenprod.internal.cn-north-4.mysql.rds.myhuaweicloud.com:13306/hydrogen?useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true # 数据库名称
|
||||
username: hydrogen_user
|
||||
password: 'EwkgCTJU$8g7'
|
||||
druid:
|
||||
# 初始化大小,最小,最大
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
max-wait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties:
|
||||
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
# 合并多个DruidDataSource的监控数据
|
||||
use-global-data-source-stat: true
|
||||
filters: stat,wall
|
||||
|
||||
redis:
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 200
|
||||
max-idle: 10
|
||||
min-idle: -1
|
||||
host: redis-6962c01f-a6ab-40c7-9ae1-6dcc29aeb6f3.cn-north-4.dcs.myhuaweicloud.com
|
||||
port: 6379
|
||||
password: juGmpEv*=p6!&*m6
|
||||
timeout: 1000
|
||||
database: 1
|
|
@ -0,0 +1,71 @@
|
|||
# 应用服务 WEB 访问端口
|
||||
server:
|
||||
port: 8007
|
||||
servlet:
|
||||
context-path: /hydrogen-applet
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
force: true
|
||||
enabled: true
|
||||
compression:
|
||||
enabled: true
|
||||
min-response-size: 1024
|
||||
mime-types:
|
||||
- image/png
|
||||
- image/jpeg
|
||||
- image/jpg
|
||||
- text/html
|
||||
- application/javascript
|
||||
- text/css
|
||||
- application/octet-stream
|
||||
- application/json
|
||||
|
||||
spring:
|
||||
jmx:
|
||||
enabled: false
|
||||
# 当前环境名称(注意:不可设置为 test 它是单元测试专用的名称)
|
||||
profiles:
|
||||
active: dev
|
||||
application:
|
||||
name: hydrogen-applet
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
||||
cloud:
|
||||
sentinel:
|
||||
transport:
|
||||
# 控制台地址
|
||||
dashboard: 127.0.0.1:8718
|
||||
eager: true
|
||||
# 声明式服务
|
||||
feign:
|
||||
# 开启okhttp客户端
|
||||
okhttp:
|
||||
enabled: true
|
||||
# 请求与响应的压缩以提高通信效率
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 2048
|
||||
mime-types: text/xml,application/xml,application/json
|
||||
response:
|
||||
enabled: true
|
||||
|
||||
httpclient:
|
||||
enabled: false
|
||||
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
|
||||
#mybatisPlus
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml #注意:一定要对应mapper映射xml文件的所在路径
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
map-underscore-to-camel-case: true
|
||||
local-cache-scope: STATEMENT
|
||||
jwt:
|
||||
secret: hydrogenUserSecret
|
||||
expiration: 604800
|
||||
tokenHead: hydrogenBearer
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false">
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<property name="LOG_HOME" value="${logPath:-${java.io.tmpdir:-.}}/logs" />
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<!--<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!–日志文件输出的文件名–>
|
||||
<FileNamePattern>${LOG_HOME}/manage.log-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
|
||||
<!–日志文件保留天数–>
|
||||
<maxHistory>30</maxHistory>
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!–格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符–>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>-->
|
||||
<logger name="com.apache.ibatis" level="TRACE"/>
|
||||
<logger name="java.sql.Connection" level="DEBUG"/>
|
||||
<logger name="java.sql.Statement" level="DEBUG"/>
|
||||
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
|
||||
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<!-- <appender-ref ref="FILE" />-->
|
||||
</root>
|
||||
<!--日志异步到数据库 -->
|
||||
<!--<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">-->
|
||||
<!--<!–日志异步到数据库 –>-->
|
||||
<!--<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">-->
|
||||
<!--<!–连接池 –>-->
|
||||
<!--<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">-->
|
||||
<!--<driverClass>com.mysql.jdbc.Driver</driverClass>-->
|
||||
<!--<url>jdbc:mysql://127.0.0.1:3306/databaseName</url>-->
|
||||
<!--<user>root</user>-->
|
||||
<!--<password>root</password>-->
|
||||
<!--</dataSource>-->
|
||||
<!--</connectionSource>-->
|
||||
<!--</appender>-->
|
||||
</configuration>
|
|
@ -0,0 +1,44 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/misc.xml
|
||||
.idea/libraries/
|
||||
.idea/misc.xml/
|
||||
.idea/vcs.xml/
|
||||
.idea/uiDesigner.xml/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
.idea/dataSources.xml
|
||||
.idea/mybatisx/templates.xml
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,127 @@
|
|||
<?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.hydrogen</groupId>
|
||||
<artifactId>hydrogen</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.hydrogen</groupId>
|
||||
<artifactId>hydrogen-brand-manager</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>hydrogen-brand-manager</name>
|
||||
<description>吸氢机品牌商管理后台</description>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- alibaba dataSource -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis-Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis-Plus 自动代码生成器 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring-cloud-alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.hydrogen</groupId>
|
||||
<artifactId>hydrogen-mbg</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>Nexus Repository</name>
|
||||
<url>http://nexus.derunht.cn/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<!-- 私服仓库配置:从私服下载-->
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>nexus</id>
|
||||
<name>Nexus Plugin Repository</name>
|
||||
<url>http://nexus.derunht.cn/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>1.4.2.RELEASE</version>
|
||||
<configuration>
|
||||
<!-- ⭐设定启动类-->
|
||||
<mainClass>com.hydrogen.brandManager.brandManagerApplication</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
package com.hydrogen;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@MapperScan(basePackages ="com.hydrogen.brandManager.dao")
|
||||
@EnableAsync
|
||||
@SpringBootApplication
|
||||
public class HydrogenBrandManagerApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HydrogenBrandManagerApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.hydrogen;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(HydrogenBrandManagerApplication.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.hydrogen.brandManager.config;
|
||||
|
||||
import feign.Logger;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Feign 客户端日志配置
|
||||
*/
|
||||
@Configuration
|
||||
public class FeignConfiguration {
|
||||
|
||||
@Bean
|
||||
Logger.Level feignLevel() {
|
||||
return Logger.Level.BASIC;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.hydrogen.brandManager.config;
|
||||
|
||||
import feign.Feign;
|
||||
import okhttp3.ConnectionPool;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName OpenFeignInterfaceConfiguration
|
||||
* @Description OpenFeignConfig 配置管理
|
||||
* @Author chaixueteng
|
||||
* @Date 2020/3/10 9:46
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(Feign.class)
|
||||
@AutoConfigureBefore(FeignAutoConfiguration.class)
|
||||
public class FeignOkHttpConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public okhttp3.OkHttpClient okHttpClient(){
|
||||
return new okhttp3.OkHttpClient.Builder()
|
||||
//设置连接超时
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
//设置读超时
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
//是否自动重连
|
||||
.retryOnConnectionFailure(true)
|
||||
// 最大连接数、连接存活时间、存活时间单位(分钟)
|
||||
.connectionPool(new ConnectionPool(200, 5, TimeUnit.MINUTES))
|
||||
//构建OkHttpClient对象
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.hydrogen.brandManager.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.hydrogen.brandManager.dao")
|
||||
public class MyBatisPlusConfig {
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
|
||||
// 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
|
||||
return interceptor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
package com.hydrogen.brandManager.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @ClassName MybatisGenerator
|
||||
* @Description mybatis生成器
|
||||
* @Author chaixueteng
|
||||
* @Date 2020/3/11 10:34
|
||||
*/
|
||||
public class MybatisGenerator {
|
||||
|
||||
private static final String MYSQL_URL ="jdbc:mysql://120.46.194.248:13306/jhqm_exam?useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true";
|
||||
private static final String MYSQL_DRIVE ="com.mysql.cj.jdbc.Driver";
|
||||
private static final String MYSQL_U ="exam_user";
|
||||
private static final String MYSQL_P ="7Js$A2LcTKy=";
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 读取控制台内容
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public static String scanner(String tip) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
StringBuilder help = new StringBuilder();
|
||||
help.append("请输入" + tip + ":");
|
||||
System.out.println(help.toString());
|
||||
if (scanner.hasNext()) {
|
||||
String ipt = scanner.next();
|
||||
if (StringUtils.isNotEmpty(ipt)) {
|
||||
return ipt;
|
||||
}
|
||||
}
|
||||
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
final String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/src/main/java");
|
||||
gc.setAuthor("linyx");
|
||||
gc.setOpen(false);
|
||||
gc.setServiceName("%sService");// service 命名方式
|
||||
gc.setServiceImplName("%sServiceImpl");// service impl 命名方式
|
||||
// 自定义文件命名,注意 %s 会自动填充表实体属性!
|
||||
gc.setMapperName("%sDao");
|
||||
gc.setXmlName("%sDao");
|
||||
gc.setFileOverride(true);
|
||||
gc.setActiveRecord(true);
|
||||
gc.setEnableCache(false);// XML 二级缓存
|
||||
gc.setBaseResultMap(true);// XML ResultMap
|
||||
gc.setBaseColumnList(true);// XML columList
|
||||
gc.setIdType(IdType.ASSIGN_ID);
|
||||
gc.setSwagger2(true);
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(MYSQL_URL);
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName(MYSQL_DRIVE);
|
||||
dsc.setUsername(MYSQL_U);
|
||||
dsc.setPassword(MYSQL_P);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
//pc.setModuleName(scanner("模块名"));
|
||||
pc.setParent("com.hydrogen.brandManager");
|
||||
pc.setEntity("entity");
|
||||
pc.setService("service");
|
||||
pc.setServiceImpl("service.impl");
|
||||
pc.setController("controller");// 设置控制器包名
|
||||
pc.setMapper("dao");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {}
|
||||
};
|
||||
|
||||
// 如果模板引擎是 freemarker
|
||||
String templatePath = "/templates/mapper.xml.ftl";
|
||||
|
||||
// 自定义输出配置
|
||||
List<FileOutConfig> focList = new ArrayList();
|
||||
// 自定义配置会被优先输出
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
// 自定义输出文件名
|
||||
return projectPath + "/src/main/resources/mapping/"
|
||||
+ tableInfo.getEntityName() + "Dao" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
// 配置模板
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
|
||||
templateConfig.setXml(null);
|
||||
mpg.setTemplate(templateConfig);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
//生成时 添加字段注解,解决数据库字段与实体类不一致问题 比如 mysql :f_id pojo:id
|
||||
strategy.setEntityTableFieldAnnotationEnable(true);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setRestControllerStyle(true);
|
||||
strategy.setInclude(scanner("表名"));
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setTablePrefix("t_exam_system_");
|
||||
strategy.setFieldPrefix("f_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.hydrogen.brandManager.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
@Configuration
|
||||
@EnableOpenApi
|
||||
@EnableKnife4j
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
Docket docket(){
|
||||
// 设置 swagger的版本
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
// 选择生成接口文档
|
||||
.select()
|
||||
// 包所在的路径
|
||||
.apis(RequestHandlerSelectors.basePackage("com.hydrogen.brandManager.controller"))
|
||||
// 当前包下所有接口都生成
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
// 接口文档初始化,也就是设置接口文档的详细信息,
|
||||
.apiInfo(
|
||||
new ApiInfoBuilder()
|
||||
.description("企业企盟考试系统接口文档")
|
||||
.version("v1.0")
|
||||
.title("API 测试文档")
|
||||
.license("Apache 2.0")
|
||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.hydrogen.brandManager.filter;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hydrogen.mbg.utils.JwtTokenUtil;
|
||||
import com.hydrogen.mbg.utils.RedisUtil;
|
||||
import com.hydrogen.mbg.vo.DrhtResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* 登陆拦截器
|
||||
*/
|
||||
@Slf4j
|
||||
public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
JwtTokenUtil jwtTokenUtil;
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
/**
|
||||
* 请求前置校验
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
* @param handler chosen handler to execute, for type and/or instance evaluation
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if ("OPTIONS".equals(request.getMethod())) {//这里通过判断请求的方法,判断此次是否是预检请求,如果是,标示,允许跨域;预检后,正式请求,这个方法参数就是我们设置的post了
|
||||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, OPTIONS, DELETE");//当判定为预检请求后,设定允许请求的方法
|
||||
response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-requested-with, Token"); //当判定为预检请求后,设定允许请求的头部类型
|
||||
response.addHeader("Access-Control-Max-Age", "1");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 从 http 请求头中取出 token
|
||||
String authorizationToken = request.getHeader("Authorization");
|
||||
if (!StringUtils.isEmpty(authorizationToken)) {
|
||||
//判断token是否有效
|
||||
return jwtTokenUtil.validateToken(authorizationToken);
|
||||
}
|
||||
|
||||
writeResponse(response);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
// String token = request.getHeader("token");
|
||||
// userDao.refreshToken(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入响应
|
||||
*
|
||||
* @param resp 响应结果
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeResponse(HttpServletResponse resp) throws IOException {
|
||||
DrhtResult<Object> fail = DrhtResult.build(1000, "请重新登陆");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
resp.setContentType("text/javascript");
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.write(JSONObject.toJSON(fail).toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.hydrogen.brandManager.filter;
|
||||
|
||||
import com.hydrogen.mbg.vo.DrhtResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 全局Controller参数校验异常处理
|
||||
*
|
||||
* @author linyx
|
||||
* @Date 2019/7/16
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalParameterValidationHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseBody
|
||||
public DrhtResult exception(MethodArgumentNotValidException e, HttpServletRequest request) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
BindingResult bindingResult = e.getBindingResult();
|
||||
log.error("请求[ {} ] {} 的参数校验发生错误", request.getMethod(), request.getRequestURL());
|
||||
for (ObjectError objectError : bindingResult.getAllErrors()) {
|
||||
FieldError fieldError = (FieldError) objectError;
|
||||
log.error("参数 {} = {} 校验错误:{}", fieldError.getField(), fieldError.getRejectedValue(), fieldError.getDefaultMessage());
|
||||
result.append(fieldError.getDefaultMessage());
|
||||
result.append(";");
|
||||
}
|
||||
return DrhtResult.build(400, result.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.hydrogen.brandManager.filter;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author fjc
|
||||
* @date 2023-10-16 17:30
|
||||
*/
|
||||
@Configuration
|
||||
public class InteceptorChainConfigFilter implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public HandlerInterceptor myIPInterceptor(){
|
||||
return new AuthenticationInterceptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(myIPInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/applet/login")
|
||||
.excludePathPatterns("/doc.html")
|
||||
.excludePathPatterns("/swagger-resources")
|
||||
.excludePathPatterns("/v2/api-docs")
|
||||
.excludePathPatterns("/v3/api-docs")
|
||||
.excludePathPatterns("/favicon.ico")
|
||||
.excludePathPatterns("/webjars/**")
|
||||
.excludePathPatterns("/upload/**");
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置跨域
|
||||
* */
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("*");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置默认资源请求路径
|
||||
* */
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
# 应用服务 WEB 访问端口
|
||||
server:
|
||||
port: 8007
|
||||
servlet:
|
||||
context-path: /exampleSystem
|
||||
compression:
|
||||
enabled: true
|
||||
min-response-size: 1024
|
||||
mime-types:
|
||||
- image/png
|
||||
- image/jpeg
|
||||
- image/jpg
|
||||
- text/html
|
||||
- application/javascript
|
||||
- text/css
|
||||
- application/octet-stream
|
||||
- application/json
|
||||
|
||||
spring:
|
||||
jmx:
|
||||
enabled: false
|
||||
application:
|
||||
name: exampleSystem
|
||||
http:
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
force: true
|
||||
enabled: true
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动包
|
||||
url: jdbc:mysql://hydrogenprod.internal.cn-north-4.mysql.rds.myhuaweicloud.com:13306/jhqm_exam?useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true # 数据库名称
|
||||
username: exam_user
|
||||
password: 'EwkgCTJU$8g7'
|
||||
druid:
|
||||
# 初始化大小,最小,最大
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
max-wait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties:
|
||||
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
# 合并多个DruidDataSource的监控数据
|
||||
use-global-data-source-stat: true
|
||||
filters: stat,wall
|
||||
|
||||
redis:
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 200
|
||||
max-idle: 10
|
||||
min-idle: -1
|
||||
host: redis-6962c01f-a6ab-40c7-9ae1-6dcc29aeb6f3.cn-north-4.dcs.myhuaweicloud.com
|
||||
port: 6379
|
||||
password: juGmpEv*=p6!&*m6
|
||||
timeout: 1000
|
||||
database: 1
|
||||
|
||||
cloud:
|
||||
sentinel:
|
||||
transport:
|
||||
# 控制台地址
|
||||
dashboard: 127.0.0.1:8718
|
||||
eager: true
|
||||
# 声明式服务
|
||||
feign:
|
||||
# 开启okhttp客户端
|
||||
okhttp:
|
||||
enabled: true
|
||||
# 请求与响应的压缩以提高通信效率
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 2048
|
||||
mime-types: text/xml,application/xml,application/json
|
||||
response:
|
||||
enabled: true
|
||||
|
||||
httpclient:
|
||||
enabled: false
|
||||
|
||||
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
|
||||
#mybatisPlus
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml #注意:一定要对应mapper映射xml文件的所在路径
|
||||
# type-aliases-package: com/hydrogen/brandManager/entity # 注意:对应实体类的路径
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
map-underscore-to-camel-case: true
|
||||
local-cache-scope: STATEMENT
|
|
@ -0,0 +1,111 @@
|
|||
# 应用服务 WEB 访问端口
|
||||
server:
|
||||
port: 8007
|
||||
servlet:
|
||||
context-path: /brandManager
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
force: true
|
||||
enabled: true
|
||||
compression:
|
||||
enabled: true
|
||||
min-response-size: 1024
|
||||
mime-types:
|
||||
- image/png
|
||||
- image/jpeg
|
||||
- image/jpg
|
||||
- text/html
|
||||
- application/javascript
|
||||
- text/css
|
||||
- application/octet-stream
|
||||
- application/json
|
||||
|
||||
spring:
|
||||
jmx:
|
||||
enabled: false
|
||||
# 当前环境名称(注意:不可设置为 test 它是单元测试专用的名称)
|
||||
profiles:
|
||||
active: local
|
||||
application:
|
||||
name: brandManager
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动包
|
||||
url: jdbc:mysql://120.46.194.248:13306/jhqm_exam?useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true # 数据库名称
|
||||
username: exam_user
|
||||
password: '7Js$A2LcTKy='
|
||||
druid:
|
||||
# 初始化大小,最小,最大
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
max-wait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1 FROM DUAL
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connect-properties:
|
||||
druid.stat.slowSqlMillis=5000
|
||||
druid.stat.mergeSql=true;
|
||||
# 合并多个DruidDataSource的监控数据
|
||||
use-global-data-source-stat: true
|
||||
filters: stat,wall
|
||||
|
||||
redis:
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 200
|
||||
max-idle: 10
|
||||
min-idle: -1
|
||||
host: 120.46.171.171
|
||||
port: 6379
|
||||
password: bcd4@g2wp*PZv#&U
|
||||
timeout: 1000
|
||||
database: 1
|
||||
|
||||
cloud:
|
||||
sentinel:
|
||||
transport:
|
||||
# 控制台地址
|
||||
dashboard: 127.0.0.1:8718
|
||||
eager: true
|
||||
# 声明式服务
|
||||
feign:
|
||||
# 开启okhttp客户端
|
||||
okhttp:
|
||||
enabled: true
|
||||
# 请求与响应的压缩以提高通信效率
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 2048
|
||||
mime-types: text/xml,application/xml,application/json
|
||||
response:
|
||||
enabled: true
|
||||
|
||||
httpclient:
|
||||
enabled: false
|
||||
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
|
||||
#mybatisPlus
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml #注意:一定要对应mapper映射xml文件的所在路径
|
||||
# type-aliases-package: com/hydrogen/brandManager/entity # 注意:对应实体类的路径
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
map-underscore-to-camel-case: true
|
||||
local-cache-scope: STATEMENT
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false">
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<property name="LOG_HOME" value="${logPath:-${java.io.tmpdir:-.}}/logs" />
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<!--<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!–日志文件输出的文件名–>
|
||||
<FileNamePattern>${LOG_HOME}/manage.log-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
|
||||
<!–日志文件保留天数–>
|
||||
<maxHistory>30</maxHistory>
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!–格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符–>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>-->
|
||||
<logger name="com.apache.ibatis" level="TRACE"/>
|
||||
<logger name="java.sql.Connection" level="DEBUG"/>
|
||||
<logger name="java.sql.Statement" level="DEBUG"/>
|
||||
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
|
||||
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<!-- <appender-ref ref="FILE" />-->
|
||||
</root>
|
||||
<!--日志异步到数据库 -->
|
||||
<!--<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">-->
|
||||
<!--<!–日志异步到数据库 –>-->
|
||||
<!--<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">-->
|
||||
<!--<!–连接池 –>-->
|
||||
<!--<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">-->
|
||||
<!--<driverClass>com.mysql.jdbc.Driver</driverClass>-->
|
||||
<!--<url>jdbc:mysql://127.0.0.1:3306/databaseName</url>-->
|
||||
<!--<user>root</user>-->
|
||||
<!--<password>root</password>-->
|
||||
<!--</dataSource>-->
|
||||
<!--</connectionSource>-->
|
||||
<!--</appender>-->
|
||||
</configuration>
|
|
@ -0,0 +1,44 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/misc.xml
|
||||
.idea/libraries/
|
||||
.idea/misc.xml/
|
||||
.idea/vcs.xml/
|
||||
.idea/uiDesigner.xml/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
.idea/dataSources.xml
|
||||
.idea/mybatisx/templates.xml
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,20 @@
|
|||
<?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.hydrogen</groupId>
|
||||
<artifactId>hydrogen</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hydrogen-mbg</artifactId>
|
||||
|
||||
<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,61 @@
|
|||
package com.hydrogen.mbg.bean;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(description = "分页数据")
|
||||
public class PageBean<T> implements Serializable {
|
||||
|
||||
@ApiModelProperty("当前页码")
|
||||
private int pageNum; //当前页码
|
||||
//@Expose gson 没有此注解的生成json时会被排除掉
|
||||
|
||||
@ApiModelProperty("每页显示的页数")
|
||||
private int pageSize; // 每页显示的页数
|
||||
|
||||
@ApiModelProperty("当前页的数据集合")
|
||||
private List<T> list; //当前页的数据集合
|
||||
|
||||
@ApiModelProperty("总记录数")
|
||||
private int total; //总记录数
|
||||
|
||||
|
||||
public int getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(int pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.hydrogen.mbg.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel(value = "列表查询基础dto")
|
||||
public class BaseListDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "当前页,从1开始")
|
||||
private Integer pageNum=1;
|
||||
@ApiModelProperty(value = "每页条数")
|
||||
private Integer pageSize=15;
|
||||
@ApiModelProperty(value = "是否分页")
|
||||
private Boolean page;
|
||||
|
||||
public BaseListDTO() {
|
||||
this.page = false;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
if(pageNum==null||pageNum==0){
|
||||
return 1;
|
||||
}
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
if(pageSize==null||pageSize==0){
|
||||
return 15;
|
||||
}
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Boolean getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Boolean page) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package com.hydrogen.mbg.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
//import io.jsonwebtoken.Claims;
|
||||
//import io.jsonwebtoken.Jwts;
|
||||
//import io.jsonwebtoken.SignatureAlgorithm;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* JwtToken生成的工具类
|
||||
* JWT token的格式:header.payload.signature
|
||||
* header的格式(算法、token的类型):
|
||||
* {"alg": "HS512","typ": "JWT"}
|
||||
* payload的格式(用户名、创建时间、生成时间):
|
||||
* {"sub":"wang","created":1489079981393,"exp":1489684781}
|
||||
* signature的生成算法:
|
||||
* HMACSHA512(base64UrlEncode(header) + "." +base64UrlEncode(payload),secret)
|
||||
*/
|
||||
@Component
|
||||
public class JwtTokenUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JwtTokenUtil.class);
|
||||
private static final String CLAIM_KEY_USERNAME = "account";
|
||||
private static final String CLAIM_KEY_USERID = "account_id";
|
||||
private static final String CLAIM_KEY_CREATED = "created";
|
||||
private static final String ISSUER = "hydrogen";
|
||||
@Value("${jwt.secret}")
|
||||
private String secret;
|
||||
@Value("${jwt.expiration}")
|
||||
private Long expiration;
|
||||
@Value("${jwt.tokenHead}")
|
||||
private String tokenHead;
|
||||
|
||||
// 创建Token
|
||||
public String createToken(String userName,String userId) {
|
||||
return tokenHead + JWT.create()
|
||||
.withIssuer(ISSUER) //发行人
|
||||
.withClaim(CLAIM_KEY_USERNAME,userName) //存放数据
|
||||
.withClaim(CLAIM_KEY_USERID,userId) //存放数据
|
||||
.withClaim(CLAIM_KEY_CREATED,new Date()) //存放数据
|
||||
// .withExpiresAt(new Date(System.currentTimeMillis() + expiration * 1000)) //过期时间,Redis处理
|
||||
.sign(Algorithm.HMAC256(secret));
|
||||
}
|
||||
//
|
||||
// 从Token中获取用户信息
|
||||
public Map<String,String> getUserInfoFromToken(String token) {
|
||||
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(secret))
|
||||
.withIssuer(ISSUER)
|
||||
.build();
|
||||
token = token.replace(tokenHead,"");
|
||||
DecodedJWT decodedJWT = jwtVerifier.verify(token);
|
||||
Map<String,String> userInfo = new HashMap<>();
|
||||
userInfo.put(CLAIM_KEY_USERNAME,decodedJWT.getClaim(CLAIM_KEY_USERNAME).asString());
|
||||
userInfo.put(CLAIM_KEY_USERID,decodedJWT.getClaim(CLAIM_KEY_USERID).asString());
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
// 验证Token是否有效
|
||||
public boolean validateToken(String token) {
|
||||
boolean isValid = true;
|
||||
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(secret))
|
||||
.withIssuer(ISSUER)
|
||||
.build();
|
||||
try {
|
||||
token = token.replace(tokenHead,"");
|
||||
DecodedJWT decodedJWT = jwtVerifier.verify(token);
|
||||
}catch(Exception e){
|
||||
isValid = false;
|
||||
LOGGER.info("token异常:"+e);;
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
// claims.put(CLAIM_KEY_USERNAME, "fujichuan");
|
||||
claims.put(CLAIM_KEY_CREATED, new Date());
|
||||
String token = JWT.create()
|
||||
.withIssuer("auth0") //发行人
|
||||
.withClaim("username","fujichuan") //存放数据
|
||||
.withClaim("created",new Date())
|
||||
.withExpiresAt(new Date(System.currentTimeMillis() + 604800 * 1000)) //过期时间
|
||||
.sign(Algorithm.HMAC256("userSecret"));
|
||||
|
||||
|
||||
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256("userSecret"))
|
||||
.withIssuer("auth0")
|
||||
.build();
|
||||
DecodedJWT decodedJWT = jwtVerifier.verify(token);/// 如果有问题的话,那么抛出各种异常
|
||||
|
||||
System.out.println("TOKEN 验证通过");
|
||||
System.out.println("username :"+ decodedJWT.getClaim("username").asString());
|
||||
System.out.println("过期时间:"+ decodedJWT.getExpiresAt());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package com.hydrogen.mbg.utils;
|
||||
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @title redis工具类
|
||||
* @author LeGreen
|
||||
* @date 2021/1/6
|
||||
*/
|
||||
@Component
|
||||
public class RedisUtil {
|
||||
|
||||
private static final String COMMON_KEY = "hydrogen-";
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 设置缓存过期时间
|
||||
* @param key 缓存Key
|
||||
* @param timeout 过期时间
|
||||
* @param unit 单位(默认为秒-TimeUnit.SECONDS)
|
||||
*/
|
||||
public void expire(String key, long timeout, TimeUnit unit) {
|
||||
key = COMMON_KEY+key;
|
||||
redisTemplate.expire(key, timeout, unit == null ? TimeUnit.SECONDS : unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存
|
||||
* @param key 缓存Key
|
||||
* @param value 缓存值
|
||||
*/
|
||||
public void setRedisValue(String key, Object value) {
|
||||
setRedisValue(key, value, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存
|
||||
* @param key 缓存Key
|
||||
* @param value 缓存值
|
||||
* @param timeout 过期时间
|
||||
* @param unit 单位(默认为秒-TimeUnit.SECONDS)
|
||||
*/
|
||||
public void setRedisValue(String key, Object value, Long timeout, TimeUnit unit) {
|
||||
key = COMMON_KEY+key;
|
||||
if(timeout == null || timeout <= 0) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
} else {
|
||||
redisTemplate.opsForValue().set(key, value, timeout, unit == null ? TimeUnit.SECONDS : unit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象缓存(String)
|
||||
* @param key 缓存Key
|
||||
* @return
|
||||
*/
|
||||
public Object getRedisValue(String key) {
|
||||
key = COMMON_KEY+key;
|
||||
return redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param keys 要删除的缓存keys
|
||||
*/
|
||||
public void delete(String ... keys) {
|
||||
if(keys == null || keys.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> keyList = new ArrayList<>();
|
||||
for(String key : keys) {
|
||||
key = COMMON_KEY+key;
|
||||
keyList.add(key);
|
||||
}
|
||||
redisTemplate.delete(keyList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param keys 要删除的缓存keys
|
||||
*/
|
||||
public void deletePattern(String ... keys) {
|
||||
if(keys == null || keys.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(String key : keys) {
|
||||
key = COMMON_KEY+key;
|
||||
redisTemplate.delete(redisTemplate.keys(key+"*"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存过期时长
|
||||
* @param key 要查询的缓存keys
|
||||
*/
|
||||
public Long getExpireTime(String key) {
|
||||
key = COMMON_KEY+key;
|
||||
return redisTemplate.opsForValue().getOperations().getExpire(key);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package com.hydrogen.mbg.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义响应结构
|
||||
*/
|
||||
@ApiModel( "统一结果集")
|
||||
public class DrhtResult<T> implements Serializable {
|
||||
|
||||
// 定义jackson对象
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
@ApiModelProperty( "响应业务状态")
|
||||
// 响应业务状态
|
||||
private Integer status;
|
||||
|
||||
// 响应消息
|
||||
@ApiModelProperty( "响应消息")
|
||||
private String msg;
|
||||
|
||||
// 响应中的数据
|
||||
@ApiModelProperty( "响应中的数据")
|
||||
private T data;
|
||||
|
||||
|
||||
public static ObjectMapper getMAPPER() {
|
||||
return MAPPER;
|
||||
}
|
||||
|
||||
public static<T> DrhtResult<T> build(Integer status, String msg, T data) {
|
||||
return new DrhtResult<>(status, msg, data);
|
||||
}
|
||||
|
||||
public static<T> DrhtResult<T> ok(T data) {
|
||||
return new DrhtResult<>(data);
|
||||
}
|
||||
|
||||
public static DrhtResult ok() {
|
||||
return new DrhtResult(null);
|
||||
}
|
||||
|
||||
public DrhtResult() {
|
||||
|
||||
}
|
||||
|
||||
public static DrhtResult build(Integer status, String msg) {
|
||||
return new DrhtResult(status, msg, null);
|
||||
}
|
||||
|
||||
public DrhtResult(Integer status, String msg, T data) {
|
||||
this.status = status;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public DrhtResult(T data) {
|
||||
this.status = 200;
|
||||
this.msg = "OK";
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
// public Boolean isOK() {
|
||||
// return this.status == 200;
|
||||
// }
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将json结果集转化为TaotaoResult对象
|
||||
*
|
||||
* @param jsonData json数据
|
||||
* @param clazz TaotaoResult中的object类型
|
||||
* @return
|
||||
*/
|
||||
public static DrhtResult formatToPojo(String jsonData, Class<?> clazz) {
|
||||
try {
|
||||
if (clazz == null) {
|
||||
return MAPPER.readValue(jsonData, DrhtResult.class);
|
||||
}
|
||||
JsonNode jsonNode = MAPPER.readTree(jsonData);
|
||||
JsonNode data = jsonNode.get("data");
|
||||
Object obj = null;
|
||||
if (clazz != null) {
|
||||
if (data.isObject()) {
|
||||
obj = MAPPER.readValue(data.traverse(), clazz);
|
||||
} else if (data.isTextual()) {
|
||||
obj = MAPPER.readValue(data.asText(), clazz);
|
||||
}
|
||||
}
|
||||
return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有object对象的转化
|
||||
*
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
public static DrhtResult format(String json) {
|
||||
try {
|
||||
return MAPPER.readValue(json, DrhtResult.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object是集合转化
|
||||
*
|
||||
* @param jsonData json数据
|
||||
* @param clazz 集合中的类型
|
||||
* @return
|
||||
*/
|
||||
public static DrhtResult formatToList(String jsonData, Class<?> clazz) {
|
||||
try {
|
||||
JsonNode jsonNode = MAPPER.readTree(jsonData);
|
||||
JsonNode data = jsonNode.get("data");
|
||||
Object obj = null;
|
||||
if (data.isArray() && data.size() > 0) {
|
||||
obj = MAPPER.readValue(data.traverse(),
|
||||
MAPPER.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||
}
|
||||
return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.hydrogen.mbg.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "列表查询基础Vo")
|
||||
public class ListVO<T> {
|
||||
|
||||
public ListVO() {
|
||||
}
|
||||
@ApiModelProperty(value = "当前页")
|
||||
private Integer pageNum;
|
||||
|
||||
@ApiModelProperty(value = "总记录数")
|
||||
private Long total;
|
||||
|
||||
@ApiModelProperty(value = "数据集")
|
||||
private List<T> list;
|
||||
|
||||
public ListVO(List<T> arr) {
|
||||
this.pageNum = 1;
|
||||
this.list = arr;
|
||||
this.total = (long)arr.size();
|
||||
}
|
||||
|
||||
public ListVO(List<T> arr, Long total) {
|
||||
this.pageNum = 1;
|
||||
this.list = arr;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public ListVO(List<T> arr, Long total, Integer pageNum){
|
||||
this.pageNum = pageNum;
|
||||
this.list = arr;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
<?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>
|
||||
|
||||
<groupId>com.hydrogen</groupId>
|
||||
<artifactId>hydrogen</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>hydrogen-applet</module>
|
||||
<module>hydrogen-brand-manager</module>
|
||||
<module>hydrogen-mbg</module>
|
||||
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>2.6.13</spring-boot.version>
|
||||
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
||||
<!-- mybatis-puls -->
|
||||
<mybatis-plus.version>3.4.0</mybatis-plus.version>
|
||||
<mybatis-generator.version>3.4.0</mybatis-generator.version>
|
||||
<!-- hutool -->
|
||||
<hutool.version>5.3.9</hutool.version>
|
||||
<!-- swagger -->
|
||||
<swagger.version>3.0.0</swagger.version>
|
||||
<!-- mybatis -->
|
||||
<mybatis.version>2.2.2</mybatis.version>
|
||||
<!-- okhttp-->
|
||||
<okhttp.version>11.10</okhttp.version>
|
||||
<!-- fastjson-->
|
||||
<fastjson.version>1.2.83</fastjson.version>
|
||||
<!-- openfeign-->
|
||||
<openfeign.version>2.2.6.RELEASE</openfeign.version>
|
||||
<pagehelper.version>1.4.1</pagehelper.version>
|
||||
<skipTests>true</skipTests>
|
||||
<mysql.version>8.0.19</mysql.version>
|
||||
<druid.version>1.1.22</druid.version>
|
||||
<elasticsearch>2.6.13</elasticsearch>
|
||||
<weixin-java-miniapp.version>4.6.0</weixin-java-miniapp.version>
|
||||
<weixin-java-mp.version>4.6.0</weixin-java-mp.version>
|
||||
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<!-- RabbitMQ-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-amqp</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.amqp</groupId>-->
|
||||
<!-- <artifactId>spring-rabbit-test</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<version>${openfeign.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
<version>${okhttp.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- freemarker 模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<!-- knife4j 3.0.2 相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>27.0.1-android</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>2.2.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.huaweicloud</groupId>
|
||||
<artifactId>esdk-obs-java-bundle</artifactId>
|
||||
<version>3.21.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>sms</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>bgmprovider</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>jca</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>jsse</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.belerweb</groupId>
|
||||
<artifactId>pinyin4j</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.biezhi</groupId>
|
||||
<artifactId>TinyPinyin</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stuxuhai</groupId>
|
||||
<artifactId>jpinyin</artifactId>
|
||||
<version>1.1.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.18.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-miniapp</artifactId>
|
||||
<version>${weixin-java-miniapp.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<version>${weixin-java-mp.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis.version}</version>
|
||||
</dependency>
|
||||
<!-- alibaba dataSource -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
<!-- MyBatis-Plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!-- MyBatis-Plus 自动代码生成器 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>${mybatis-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
<!--pageInfo-->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>${pagehelper.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring-cloud-alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue