Commit 03a1b37f authored by zhangc's avatar zhangc

commit

parent df27bbc5
...@@ -136,6 +136,20 @@ ...@@ -136,6 +136,20 @@
<groupId>org.springframework.session</groupId> <groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId> <artifactId>spring-session-data-redis</artifactId>
</dependency> </dependency>
<!-- 代码自动生成依赖 begin -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.4.1</version>
</dependency>
<!-- velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
<!-- 代码自动生成依赖 end-->
</dependencies> </dependencies>
<build> <build>
......
...@@ -27,6 +27,13 @@ public class MybatisPlusConfig { ...@@ -27,6 +27,13 @@ public class MybatisPlusConfig {
paginationInterceptor.setLimit(500); paginationInterceptor.setLimit(500);
// 开启 count 的 join 优化,只针对部分 left join // 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true)); paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor; return paginationInterceptor;
} }
/* @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor plusInterceptor =new MybatisPlusInterceptor();
// plusInterceptor.addInnerInterceptor();
return plusInterceptor;
}*/
} }
package com.jz.dm.config; package com.jz.dm.config;
import com.jz.dm.web.interceptor.AccessLimitInterceptor; import com.jz.dm.web.interceptor.AccessLimitInterceptor;
import com.jz.dm.web.request.ApiGatewayRequestInterceptor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
...@@ -29,6 +30,8 @@ public class WebAppConfigurer extends WebMvcConfigurerAdapter { ...@@ -29,6 +30,8 @@ public class WebAppConfigurer extends WebMvcConfigurerAdapter {
"/**/*.js", //js静态资源 "/**/*.js", //js静态资源
"/**/*.css" //css静态资源 "/**/*.css" //css静态资源
); );
} }
@Bean @Bean
public AccessLimitInterceptor getAccessLimitInterceptor() { public AccessLimitInterceptor getAccessLimitInterceptor() {
......
...@@ -9,6 +9,7 @@ import com.jz.dm.models.enity.GatewayRequest; ...@@ -9,6 +9,7 @@ import com.jz.dm.models.enity.GatewayRequest;
import com.jz.dm.models.enity.GatewayResponse; import com.jz.dm.models.enity.GatewayResponse;
import com.jz.dm.models.enity.RequestContext; import com.jz.dm.models.enity.RequestContext;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -35,17 +36,18 @@ public class GatewayController { ...@@ -35,17 +36,18 @@ public class GatewayController {
//@RequestMapping(value = "/gateway", consumes = "application/json") //@RequestMapping(value = "/gateway", consumes = "application/json")
@PostMapping(value="/gateway",consumes = "application/json") @PostMapping(value="/gateway",consumes = "application/json")
@ApiOperation(value = "Api请求接口")
public String gateway(@RequestBody String json, HttpServletRequest httpServletRequest, public String gateway(@RequestBody String json, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) { HttpServletResponse httpServletResponse) {
GatewayRequest gatewayRequest = JSON.parseObject(json, GatewayRequest.class); GatewayRequest gatewayRequest = JSON.parseObject(json, GatewayRequest.class);
return doGateway(gatewayRequest, httpServletRequest, httpServletResponse); return doGateway(gatewayRequest, httpServletRequest, httpServletResponse);
} }
@RequestMapping(value = "/gateway") /* @RequestMapping(value = "/gateway")
public String gateway(GatewayRequest gatewayRequest, HttpServletRequest httpServletRequest, public String gateway(GatewayRequest gatewayRequest, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) { HttpServletResponse httpServletResponse) {
return doGateway(gatewayRequest, httpServletRequest, httpServletResponse); return doGateway(gatewayRequest, httpServletRequest, httpServletResponse);
} }*/
private String doGateway(GatewayRequest gatewayRequest, HttpServletRequest httpServletRequest, private String doGateway(GatewayRequest gatewayRequest, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) { HttpServletResponse httpServletResponse) {
......
...@@ -45,7 +45,8 @@ public class DefaultOpenApiDispatcher implements OpenApiDispatcher { ...@@ -45,7 +45,8 @@ public class DefaultOpenApiDispatcher implements OpenApiDispatcher {
@Resource @Resource
public void setOpenApiServices(List<OpenApiService> openApiServiceList) { public void setOpenApiServices(List<OpenApiService> openApiServiceList) {
for (OpenApiService openApiService : openApiServiceList) { for (OpenApiService openApiService : openApiServiceList) {
String openApiServiceKey = getOpenApiServiceKey(openApiService.getOpenApiMethod(),openApiService.getOpenApiVersion()); String openApiServiceKey = getOpenApiServiceKey(openApiService.getOpenApiMethod(),
openApiService.getOpenApiVersion());
openApiServices.put(openApiServiceKey, openApiService); openApiServices.put(openApiServiceKey, openApiService);
} }
} }
......
package com.jz.dm.generate;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
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.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.apache.commons.lang3.StringUtils;
import java.util.Scanner;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.generate
* @PROJECT_NAME: jz-dm-parent
* @NAME: MybatisPlusGenerate
* @DATE: 2021-1-30/12:43
* @DAY_NAME_SHORT: 周六
* @Description:
**/
public class MybatisPlusGenerate {
public static void main(String[] args) {
//1. 全局配置
GlobalConfig config = new GlobalConfig();
// 是否支持AR模式
config.setActiveRecord(true)
// 作者
.setAuthor("ZC")
// 生成路径,最好使用绝对路径,window路径是不一样的
//TODO TODO TODO TODO
.setOutputDir("/Users/xdclass/Desktop/demo/src/main/java")
// 文件覆盖
.setFileOverride(true)
// 主键策略
.setIdType(IdType.AUTO)
.setDateType(DateType.ONLY_DATE)
// 设置生成的service接口的名字的首字母是否为I,默认Service是以I开头的
.setServiceName("%sService")
//实体类结尾名称
.setEntityName("%sDO")
//生成基本的resultMap
.setBaseResultMap(true)
//不使用AR模式
.setActiveRecord(false)
//生成基本的SQL片段
.setBaseColumnList(true);
//2. 数据源配置
DataSourceConfig dsConfig = new DataSourceConfig();
// 设置数据库类型
dsConfig.setDbType(DbType.MYSQL)
.setDriverName("com.mysql.cj.jdbc.Driver")
//TODO TODO TODO TODO
.setUrl("jdbc:mysql://127.0.0.1:3306/xd_shop?useSSL=false")
.setUsername("root")
.setPassword("xdclass.net");
//3. 策略配置globalConfiguration中
StrategyConfig stConfig = new StrategyConfig();
//全局大写命名
stConfig.setCapitalMode(true)
// 数据库表映射到实体的命名策略
.setNaming(NamingStrategy.underline_to_camel)
//使用lombok
.setEntityLombokModel(true)
//使用restcontroller注解
.setRestControllerStyle(true)
// 生成的表, 支持多表一起生成,以数组形式填写
//TODO TODO TODO TODO 两个方式,直接写,或者使用命令行输入
.setInclude("product", "banner", "address", "coupon", "product_order");
//.setInclude(scanner("表名,多个英文逗号分割").split(","));
//TODO TODO TODO TODO
//4. 包名策略配置(生成的项目包名)
PackageConfig pkConfig = new PackageConfig();
pkConfig.setParent("net.xdclass.shopmanager")
.setMapper("mapper")
.setService("service")
.setController("controller")
.setEntity("model")
.setXml("mapper");
//5. 整合配置
AutoGenerator ag = new AutoGenerator();
ag.setGlobalConfig(config)
.setDataSource(dsConfig)
.setStrategy(stConfig)
.setPackageInfo(pkConfig);
//6. 执行操作
ag.execute();
System.out.println("======= 小滴课堂 Done 相关代码生成完毕 ========");
}
/**
* <p>
* 读取控制台内容
* </p>
*/
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.isNotBlank(ipt)) {
return ipt;
}
}
throw new MybatisPlusException("请输入正确的" + tip + "!");
}
}
...@@ -94,7 +94,7 @@ public class GatewayRequest implements Serializable { ...@@ -94,7 +94,7 @@ public class GatewayRequest implements Serializable {
public String toString() { public String toString() {
return "GatewayRequest [appKey=" + apiKey + ", method=" + method + ", format=" + format return "GatewayRequest [appKey=" + apiKey + ", method=" + method + ", format=" + format
+ ", signType=" + signType + ", sign=" + sign + ", signType=" + signType + ", sign=" + sign
+ ", timestamp=" + timestamp + ", version=" + version + ", timestamp=" + timestamp
+ ", params=" + params + ", extAttributes=" + ", params=" + params + ", extAttributes="
+ extAttributes + "]"; + extAttributes + "]";
} }
......
...@@ -3,7 +3,6 @@ package com.jz.dm.models.resp; ...@@ -3,7 +3,6 @@ package com.jz.dm.models.resp;
import com.jz.common.bean.BasePageBean; import com.jz.common.bean.BasePageBean;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -19,7 +18,6 @@ import java.io.Serializable; ...@@ -19,7 +18,6 @@ import java.io.Serializable;
**/ **/
@Data @Data
@ApiModel @ApiModel
@Builder
public class SendDataReq extends BasePageBean implements Serializable { public class SendDataReq extends BasePageBean implements Serializable {
@ApiModelProperty(value = "关键词") @ApiModelProperty(value = "关键词")
......
...@@ -47,12 +47,12 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService { ...@@ -47,12 +47,12 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
@Override @Override
public String getOpenApiMethod() { public String getOpenApiMethod() {
return "query"; return "data.query";
} }
@Override @Override
public String getOpenApiVersion() { public String getOpenApiVersion() {
return "v1.0.0"; return "1.0.0";
} }
@Autowired @Autowired
......
...@@ -41,7 +41,7 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic ...@@ -41,7 +41,7 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
@Override @Override
public String getOpenApiVersion() { public String getOpenApiVersion() {
return "v1.0.0"; return "v1.0.2";
} }
@Autowired @Autowired
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment