forked from lenve/javaboy-code-samples
-
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
Showing
24 changed files
with
604 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,50 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.4.3</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>org.javaboy</groupId> | ||
<artifactId>encode_resp</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>encode_resp</name> | ||
<description>Demo project for Spring Boot</description> | ||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.lenve</groupId> | ||
<artifactId>encrypt-spring-boot-starter</artifactId> | ||
<version>0.0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
encode_resp/src/main/java/org/javaboy/encode_resp/EncodeRespApplication.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,13 @@ | ||
package org.javaboy.encode_resp; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class EncodeRespApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(EncodeRespApplication.class, args); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
encode_resp/src/main/java/org/javaboy/encode_resp/HelloController.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,37 @@ | ||
package org.javaboy.encode_resp; | ||
|
||
import org.javaboy.encode_resp.model.User; | ||
import org.javaboy.encrypt.starter.anno.Decrypt; | ||
import org.javaboy.encrypt.starter.anno.Encrypt; | ||
import org.javaboy.encrypt.starter.model.RespBean; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@RestController | ||
public class HelloController { | ||
@GetMapping("/user") | ||
@Encrypt | ||
public RespBean getUser() { | ||
User user = new User(); | ||
user.setId((long) 99); | ||
user.setUsername("javaboy"); | ||
return RespBean.ok("ok", user); | ||
} | ||
|
||
@PostMapping("/user") | ||
public RespBean addUser(@RequestBody @Decrypt User user) { | ||
System.out.println("user = " + user); | ||
return RespBean.ok("ok", user); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
encode_resp/src/main/java/org/javaboy/encode_resp/model/User.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,39 @@ | ||
package org.javaboy.encode_resp.model; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
public class User { | ||
private Long id; | ||
private String username; | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"id=" + id + | ||
", username='" + username + '\'' + | ||
'}'; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
} |
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 @@ | ||
spring.encrypt.key=1234567890123456 |
13 changes: 13 additions & 0 deletions
13
encode_resp/src/test/java/org/javaboy/encode_resp/EncodeRespApplicationTests.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,13 @@ | ||
package org.javaboy.encode_resp; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class EncodeRespApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
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,22 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.javaboy</groupId> | ||
<artifactId>encrypt-spring-boot-starter</artifactId> | ||
<version>0.0.1</version> | ||
<name>encrypt-spring-boot-starter</name> | ||
<description>SpringBoot加密工具类</description> | ||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>provided</scope> | ||
<version>2.4.3</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
20 changes: 20 additions & 0 deletions
20
encrypt-spring-boot-starter/src/main/java/org/javaboy/encrypt/starter/anno/Decrypt.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,20 @@ | ||
package org.javaboy.encrypt.starter.anno; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD,ElementType.PARAMETER}) | ||
public @interface Decrypt { | ||
} |
20 changes: 20 additions & 0 deletions
20
encrypt-spring-boot-starter/src/main/java/org/javaboy/encrypt/starter/anno/Encrypt.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,20 @@ | ||
package org.javaboy.encrypt.starter.anno; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Encrypt { | ||
} |
19 changes: 19 additions & 0 deletions
19
...tarter/src/main/java/org/javaboy/encrypt/starter/autoconfig/EncryptAutoConfiguration.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,19 @@ | ||
package org.javaboy.encrypt.starter.autoconfig; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@Configuration | ||
@ComponentScan("org.javaboy.encrypt.starter") | ||
public class EncryptAutoConfiguration { | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
encrypt-spring-boot-starter/src/main/java/org/javaboy/encrypt/starter/model/RespBean.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,72 @@ | ||
package org.javaboy.encrypt.starter.model; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
public class RespBean { | ||
private Integer status; | ||
private String msg; | ||
private Object obj; | ||
|
||
public static RespBean build() { | ||
return new RespBean(); | ||
} | ||
|
||
public static RespBean ok(String msg) { | ||
return new RespBean(200, msg, null); | ||
} | ||
|
||
public static RespBean ok(String msg, Object obj) { | ||
return new RespBean(200, msg, obj); | ||
} | ||
|
||
public static RespBean error(String msg) { | ||
return new RespBean(500, msg, null); | ||
} | ||
|
||
public static RespBean error(String msg, Object obj) { | ||
return new RespBean(500, msg, obj); | ||
} | ||
|
||
private RespBean() { | ||
} | ||
|
||
private RespBean(Integer status, String msg, Object obj) { | ||
this.status = status; | ||
this.msg = msg; | ||
this.obj = obj; | ||
} | ||
|
||
public Integer getStatus() { | ||
return status; | ||
} | ||
|
||
public RespBean setStatus(Integer status) { | ||
this.status = status; | ||
return this; | ||
} | ||
|
||
public String getMsg() { | ||
return msg; | ||
} | ||
|
||
public RespBean setMsg(String msg) { | ||
this.msg = msg; | ||
return this; | ||
} | ||
|
||
public Object getObj() { | ||
return obj; | ||
} | ||
|
||
public RespBean setObj(Object obj) { | ||
this.obj = obj; | ||
return this; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...spring-boot-starter/src/main/java/org/javaboy/encrypt/starter/prop/EncryptProperties.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,26 @@ | ||
package org.javaboy.encrypt.starter.prop; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* @author 江南一点雨 | ||
* @微信公众号 江南一点雨 | ||
* @网站 http://www.itboyhub.com | ||
* @国际站 http://www.javaboy.org | ||
* @微信 a_java_boy | ||
* @GitHub https://github.com/lenve | ||
* @Gitee https://gitee.com/lenve | ||
*/ | ||
@ConfigurationProperties(prefix = "spring.encrypt") | ||
public class EncryptProperties { | ||
private final static String DEFAULT_KEY = "www.itboyhub.com"; | ||
private String key = DEFAULT_KEY; | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
} |
Oops, something went wrong.