forked from benwang6/spring-cloud-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d922eeb
Showing
63 changed files
with
3,309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>sp01-commons</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<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>cn.tedu</groupId> | ||
<artifactId>sp01-commons</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>sp01-commons</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.module</groupId> | ||
<artifactId>jackson-module-parameter-names</artifactId> | ||
<version>2.9.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jdk8</artifactId> | ||
<version>2.9.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
<version>2.9.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-guava</artifactId> | ||
<version>2.9.8</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.26</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.9</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cn.tedu.sp01.pojo; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Item { | ||
private Integer id; | ||
private String name; | ||
private Integer number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.tedu.sp01.pojo; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Order { | ||
private String id; | ||
private User user; | ||
private List<Item> items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cn.tedu.sp01.pojo; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class User { | ||
private Integer id; | ||
private String username; | ||
private String password; | ||
} |
10 changes: 10 additions & 0 deletions
10
sp01-commons/src/main/java/cn/tedu/sp01/service/ItemService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.tedu.sp01.service; | ||
|
||
import java.util.List; | ||
|
||
import cn.tedu.sp01.pojo.Item; | ||
|
||
public interface ItemService { | ||
List<Item> getItems(String orderId); | ||
void decreaseNumbers(List<Item> list); | ||
} |
9 changes: 9 additions & 0 deletions
9
sp01-commons/src/main/java/cn/tedu/sp01/service/OrderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cn.tedu.sp01.service; | ||
|
||
|
||
import cn.tedu.sp01.pojo.Order; | ||
|
||
public interface OrderService { | ||
Order getOrder(String orderId); | ||
void addOrder(Order order); | ||
} |
8 changes: 8 additions & 0 deletions
8
sp01-commons/src/main/java/cn/tedu/sp01/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cn.tedu.sp01.service; | ||
|
||
import cn.tedu.sp01.pojo.User; | ||
|
||
public interface UserService { | ||
User getUser(Integer id); | ||
void addScore(Integer id, Integer score); | ||
} |
62 changes: 62 additions & 0 deletions
62
sp01-commons/src/main/java/cn/tedu/web/util/CookieUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cn.tedu.web.util; | ||
|
||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class CookieUtil { | ||
|
||
/** | ||
* @param response | ||
* @param name | ||
* @param value | ||
* @param maxAge | ||
*/ | ||
public static void setCookie(HttpServletResponse response, | ||
String name, String value, String domain, String path, int maxAge) { | ||
Cookie cookie = new Cookie(name, value); | ||
if(domain != null) { | ||
cookie.setDomain(domain); | ||
} | ||
cookie.setPath(path); | ||
cookie.setMaxAge(maxAge); | ||
response.addCookie(cookie); | ||
} | ||
public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) { | ||
setCookie(response, name, value, null, "/", maxAge); | ||
} | ||
public static void setCookie(HttpServletResponse response, String name, String value) { | ||
setCookie(response, name, value, null, "/", 3600); | ||
} | ||
public static void setCookie(HttpServletResponse response, String name) { | ||
setCookie(response, name, "", null, "/", 3600); | ||
} | ||
|
||
/** | ||
* @param request | ||
* @param name | ||
* @return | ||
*/ | ||
public static String getCookie(HttpServletRequest request, String name) { | ||
String value = null; | ||
Cookie[] cookies = request.getCookies(); | ||
if (null != cookies) { | ||
for (Cookie cookie : cookies) { | ||
if (cookie.getName().equals(name)) { | ||
value = cookie.getValue(); | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
/** | ||
* @param response | ||
* @param name | ||
* @return | ||
*/ | ||
public static void removeCookie(HttpServletResponse response, String name, String domain, String path) { | ||
setCookie(response, name, "", domain, path, 0); | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
sp01-commons/src/main/java/cn/tedu/web/util/JsonResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package cn.tedu.web.util; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class JsonResult<T> { | ||
/** 成功 */ | ||
public static final int SUCCESS = 200; | ||
|
||
/** 没有登录 */ | ||
public static final int NOT_LOGIN = 400; | ||
|
||
/** 发生异常 */ | ||
public static final int EXCEPTION = 401; | ||
|
||
/** 系统错误 */ | ||
public static final int SYS_ERROR = 402; | ||
|
||
/** 参数错误 */ | ||
public static final int PARAMS_ERROR = 403; | ||
|
||
/** 不支持或已经废弃 */ | ||
public static final int NOT_SUPPORTED = 410; | ||
|
||
/** AuthCode错误 */ | ||
public static final int INVALID_AUTHCODE = 444; | ||
|
||
/** 太频繁的调用 */ | ||
public static final int TOO_FREQUENT = 445; | ||
|
||
/** 未知的错误 */ | ||
public static final int UNKNOWN_ERROR = 499; | ||
|
||
private int code; | ||
private String msg; | ||
private T data; | ||
|
||
|
||
|
||
public static JsonResult build() { | ||
return new JsonResult(); | ||
} | ||
public static JsonResult build(int code) { | ||
return new JsonResult().code(code); | ||
} | ||
public static JsonResult build(int code, String msg) { | ||
return new JsonResult<String>().code(code).msg(msg); | ||
} | ||
public static <T> JsonResult<T> build(int code, T data) { | ||
return new JsonResult<T>().code(code).data(data); | ||
} | ||
public static <T> JsonResult<T> build(int code, String msg, T data) { | ||
return new JsonResult<T>().code(code).msg(msg).data(data); | ||
} | ||
|
||
public JsonResult<T> code(int code) { | ||
this.code = code; | ||
return this; | ||
} | ||
public JsonResult<T> msg(String msg) { | ||
this.msg = msg; | ||
return this; | ||
} | ||
public JsonResult<T> data(T data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
|
||
public static JsonResult ok() { | ||
return build(SUCCESS); | ||
} | ||
public static JsonResult ok(String msg) { | ||
return build(SUCCESS, msg); | ||
} | ||
public static <T> JsonResult<T> ok(T data) { | ||
return build(SUCCESS, data); | ||
} | ||
public static JsonResult err() { | ||
return build(EXCEPTION); | ||
} | ||
public static JsonResult err(String msg) { | ||
return build(EXCEPTION, msg); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return JsonUtil.to(this); | ||
} | ||
} |
Oops, something went wrong.