admin 模块
yml

spring: application: name: mall-admin profiles: active: dev #默认为开发环境 servlet: multipart: enabled: true #开启文件上传 max-file-size: 10MB #限制文件上传大小为10M mybatis: mapper-locations: - classpath:dao/*.xml - classpath*:com/**/mapper/*.xml jwt: tokenHeader: Authorization #JWT存储的请求头 secret: mall-admin-secret #JWT加解密使用的密钥 expiration: 604800 #JWT的超期限时间(60*60*24*7) tokenHead: 'Bearer ' #JWT负载中拿到开头 redis: database: mall key: admin: 'ums:admin' resourceList: 'ums:resourceList' expire: common: 86400 # 24小时 secure: ignored: urls: #安全路径白名单 - /swagger-ui.html - /swagger-resources/** - /swagger/** - /**/v2/api-docs - /**/*.js - /**/*.css - /**/*.png - /**/*.ico - /webjars/springfox-swagger-ui/** - /actuator/** - /druid/** - /admin/login - /admin/register - /admin/info - /admin/logout - /minio/upload aliyun: oss: endpoint: oss-cn-shenzhen.aliyuncs.com # oss对外服务的访问域名 accessKeyId: test # 访问身份验证中用到用户标识 accessKeySecret: test # 用户用于加密签名字符串和oss用来验证签名字符串的密钥 bucketName: macro-oss # oss的存储空间 policy: expire: 300 # 签名有效期(S) maxSize: 10 # 上传文件大小(M) callback: http://39.98.190.128:8080/aliyun/oss/callback # 文件上传成功后的回调地址 dir: prefix: mall/images/ # 上传文件夹路径前缀 minio: endpoint: http://192.168.3.101:9090 #MinIO服务所在地址 bucketName: mall #存储桶名称 accessKey: minioadmin #访问的key secretKey: minioadmin #访问的秘钥
yml-dev

spring: datasource: url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: 123456 druid: initial-size: 5 #连接池初始化大小 min-idle: 10 #最小空闲连接数 max-active: 20 #最大连接数 web-stat-filter: exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据 stat-view-servlet: #访问监控网页的登录用户名和密码 login-username: druid login-password: druid redis: host: localhost # Redis服务器地址 database: 0 # Redis数据库索引(默认为0) port: 6379 # Redis服务器连接端口 password: # Redis服务器连接密码(默认为空) timeout: 300ms # 连接超时时间(毫秒) logging: level: root: info com.macro.mall: debug logstash: host: localhost
config
跨域配置

package com.macro.mall.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; /** * 全局跨域配置 * Created by macro on 2019/7/27. */ @Configuration public class GlobalCorsConfig { /** * 允许跨域调用的过滤器 */ @Bean public CorsFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); //允许所有域名进行跨域调用 config.addAllowedOrigin("*"); //允许跨越发送cookie config.setAllowCredentials(true); //放行全部原始头信息 config.addAllowedHeader("*"); //允许所有请求方法跨域调用 config.addAllowedMethod("*"); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); } }
MyBatisConfig

1 package com.macro.mall.config; 2 3 import org.mybatis.spring.annotation.MapperScan; 4 import org.springframework.context.annotation.Configuration; 5 import org.springframework.transaction.annotation.EnableTransactionManagement; 6 7 /** 8 * MyBatis相关配置 9 * Created by macro on 2019/4/8. 10 */ 11 @Configuration 12 @EnableTransactionManagement 13 @MapperScan({"com.macro.mall.mapper","com.macro.mall.dao"}) 14 public class MyBatisConfig { 15 }
SwaggerConfig

1 package com.macro.mall.config; 2 3 import com.macro.mall.common.config.BaseSwaggerConfig; 4 import com.macro.mall.common.domain.SwaggerProperties; 5 import org.springframework.context.annotation.Configuration; 6 import springfox.documentation.swagger2.annotations.EnableSwagger2; 7 8 /** 9 * Swagger API文档相关配置 10 * Created by macro on 2018/4/26. 11 */ 12 @Configuration 13 @EnableSwagger2 14 public class SwaggerConfig extends BaseSwaggerConfig { 15 16 @Override 17 public SwaggerProperties swaggerProperties() { 18 return SwaggerProperties.builder() 19 .apiBasePackage("com.macro.mall.controller") 20 .title("mall后台系统") 21 .description("mall后台相关接口文档") 22 .contactName("macro") 23 .version("1.0") 24 .enableSecurity(true) 25 .build(); 26 } 27 }
列子

package com.macro.mall.controller; import com.macro.mall.common.api.CommonPage; import com.macro.mall.common.api.CommonResult; import com.macro.mall.model.CmsSubject; import com.macro.mall.service.CmsSubjectService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; /** * 商品专题管理Controller * Created by macro on 2018/6/1. */ @Controller @Api(tags = "CmsSubjectController", description = "商品专题管理") @RequestMapping("/subject") public class CmsSubjectController { @Autowired private CmsSubjectService subjectService; @ApiOperation("获取全部商品专题") @RequestMapping(value = "/listAll", method = RequestMethod.GET) @ResponseBody public CommonResult<List<CmsSubject>> listAll() { List<CmsSubject> subjectList = subjectService.listAll(); return CommonResult.success(subjectList); } @ApiOperation(value = "根据专题名称分页获取商品专题") @RequestMapping(value = "/list", method = RequestMethod.GET) @ResponseBody public CommonResult<CommonPage<CmsSubject>> getList(@RequestParam(value = "keyword", required = false) String keyword, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) { List<CmsSubject> subjectList = subjectService.list(keyword, pageNum, pageSize); return CommonResult.success(CommonPage.restPage(subjectList)); } }
pom

<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.macro.mall</groupId> <artifactId>mall-admin</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>mall-admin</name> <description>mall-admin project for mall</description> <parent> <groupId>com.macro.mall</groupId> <artifactId>mall</artifactId> <version>1.0-SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>com.macro.mall</groupId> <artifactId>mall-mbg</artifactId> </dependency> <dependency> <groupId>com.macro.mall</groupId> <artifactId>mall-security</artifactId> </dependency> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> </dependency> <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.60</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> </plugin> </plugins> </build> </project>