Skip to content

Commit

Permalink
项目结构改造
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozheng committed Apr 20, 2019
1 parent cdd332a commit b580085
Show file tree
Hide file tree
Showing 34 changed files with 500 additions and 634 deletions.
55 changes: 7 additions & 48 deletions mall-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,35 @@

<groupId>com.macro.mall</groupId>
<artifactId>mall-admin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mall-admin</name>
<description>mall-admin project for mall</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<skipTests>true</skipTests>
</properties>

<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>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--MyBatis分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
<!--Swagger-UI API文档生产工具-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<!--JWT(Json Web Token)登录支持-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
Expand All @@ -86,12 +51,6 @@
<artifactId>logstash-logback-encoder</artifactId>
<version>4.8</version>
</dependency>
<!--集成druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!--lombok依赖-->
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
39 changes: 39 additions & 0 deletions mall-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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.macro.mall</groupId>
<artifactId>mall-common</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mall-common</name>
<description>mall-common project for mall</description>

<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
<!--Swagger-UI API文档生产工具-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.1.5.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.macro.mall.demo.dto;
package com.macro.mall.common.api;

import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;

import java.util.List;

Expand All @@ -14,18 +15,30 @@ public class CommonPage<T> {
private List<T> list;

/**
* 将PageHelper分页后的list转为分页信息
* 将PageHelper分页后的list转为分页信息
*/
public static <T> CommonPage<T> restPage(List<T> list) {
CommonPage<T> result = new CommonPage<>();
PageInfo<T> pageInfo = new PageInfo<>(list);
CommonPage<T> result = new CommonPage<T>();
PageInfo<T> pageInfo = new PageInfo<T>(list);
result.setTotalPage(pageInfo.getTotal() / pageInfo.getPageSize());
result.setPageNum(pageInfo.getPageNum());
result.setPageSize(pageInfo.getPageSize());
result.setList(pageInfo.getList());
return result;
}

/**
* 将SpringData分页后的list转为分页信息
*/
public static <T> CommonPage<T> restPage(Page<T> pageInfo) {
CommonPage<T> result = new CommonPage<T>();
result.setTotalPage((long) pageInfo.getTotalPages());
result.setPageNum(pageInfo.getNumber());
result.setPageSize(pageInfo.getSize());
result.setList(pageInfo.getContent());
return result;
}

public Integer getPageNum() {
return pageNum;
}
Expand Down
118 changes: 118 additions & 0 deletions mall-common/src/main/java/com/macro/mall/common/api/CommonResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.macro.mall.common.api;

/**
* 通用返回对象
*/
public class CommonResult<T> {
private long code;
private String message;
private T data;

/**
* 普通成功返回
*
* @param data 获取的数据
*/
public static <T> CommonResult<T> success(T data) {
CommonResult<T> result = new CommonResult<T>();
result.setCode(ResultCode.SUCCESS.getCode());
result.setMessage(ResultCode.SUCCESS.getMsg());
result.setData(data);
return result;
}

/**
* 普通成功返回
*
* @param data 获取的数据
*/
public static <T> CommonResult<T> success(T data,String message) {
CommonResult<T> result = new CommonResult<T>();
result.setCode(ResultCode.SUCCESS.getCode());
result.setMessage(message);
result.setData(data);
return result;
}

/**
* 通过错误码对象构造返回结果
*/
public static <T> CommonResult<T> failed(IErrorCode errorCode) {
CommonResult<T> result = new CommonResult<T>();
result.setCode(errorCode.getCode());
result.setMessage(errorCode.getMsg());
return result;
}

/**
* 普通失败提示信息
*/
public static <T> CommonResult<T> failed(String message) {
CommonResult<T> result = new CommonResult<T>();
result.setCode(ResultCode.FAILED.getCode());
result.setMessage(message);
return result;
}

/**
* 普通操作失败
*/
public static <T> CommonResult<T> failed() {
return failed(ResultCode.FAILED);
}

/**
* 参数验证失败使用
*/
public static <T> CommonResult<T> validateFailed() {
return failed(ResultCode.VALIDATE_FAILED);
}

/**
* 参数验证失败使用
*/
public static <T> CommonResult<T> validateFailed(String message) {
CommonResult<T> result = new CommonResult<T>();
result.setCode(ResultCode.FAILED.getCode());
result.setMessage(message);
return result;
}

/**
* 用户没有登录
*/
public static <T> CommonResult<T> unauthorized() {
return failed(ResultCode.UNAUTHORIZED);
}

/**
* 用户没有相应权限
*/
public static <T> CommonResult<T> forbidden() {
return failed(ResultCode.UNAUTHORIZED);
}

public long getCode() {
return code;
}

public void setCode(long code) {
this.code = code;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public T getData() {
return data;
}

public void setData(T data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.macro.mall.common.api;

/**
* 封装API的错误码
* Created by macro on 2019/4/19.
*/
public interface IErrorCode {
long getCode();

String getMsg();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.macro.mall.common.api;

/**
* 枚举了一些常用API操作码
* Created by macro on 2019/4/19.
*/
public enum ResultCode implements IErrorCode {
SUCCESS(200, "操作成功"),
FAILED(500, "操作失败"),
VALIDATE_FAILED(404, "参数检验失败"),
UNAUTHORIZED(401, "暂未登录或token已经过期"),
FORBIDDEN(403, "没有相关权限");
private long code;
private String msg;

private ResultCode(long code, String msg) {
this.code = code;
this.msg = msg;
}

public long getCode() {
return code;
}

public String getMsg() {
return msg;
}
}
Loading

0 comments on commit b580085

Please sign in to comment.