forked from yudaocode/SpringBoot-Labs
-
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
YunaiV
committed
Dec 19, 2020
1 parent
8652a4c
commit bfc48cf
Showing
7 changed files
with
167 additions
and
1 deletion.
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,23 @@ | ||
<?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"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.1.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-71-idea-http-client</artifactId> | ||
|
||
<dependencies> | ||
<!-- 实现对 Spring MVC 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...-debug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/Application.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 cn.iocoder.springboot.lab71; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.http
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,18 @@ | ||
### 测试 /user/login:登陆成功 | ||
POST http://127.0.0.1:8080/user/login | ||
Content-Type: application/x-www-form-urlencoded | ||
|
||
username=yudaoyuanma&password=123456 | ||
|
||
### 测试 /user/get-current:获取成功 | ||
GET http://127.0.0.1:8080/user/get-current | ||
Authorization: token001 | ||
|
||
### 测试 /user/update:更新成功 | ||
POST http://127.0.0.1:8080/user/update | ||
Content-Type: application/json | ||
|
||
{ | ||
"nickname": "我是昵称", | ||
"gender": 1 | ||
} |
50 changes: 50 additions & 0 deletions
50
...idea-http-client/src/main/java/cn/iocoder/springboot/lab71/controller/UserController.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,50 @@ | ||
package cn.iocoder.springboot.lab71.controller; | ||
|
||
import cn.iocoder.springboot.lab71.vo.UserUpdateVO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 用户 Controller | ||
* | ||
* 示例代码,纯粹为了演示。 | ||
*/ | ||
@RestController | ||
public class UserController { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@PostMapping("/user/login") | ||
public Map<String, Object> login(@RequestParam("username") String username, | ||
@RequestParam("password") String password) { | ||
if ("yudaoyuanma".equals(username) && "123456".equals(password)) { | ||
Map<String, Object> tokenMap = new HashMap<>(); | ||
tokenMap.put("userId", 1); | ||
tokenMap.put("token", "token001"); | ||
return tokenMap; | ||
} | ||
throw new RuntimeException("小朋友,你的账号密码不正确哟!"); | ||
} | ||
|
||
@GetMapping("/user/get-current") | ||
public Map<String, Object> getCurrentUser(@RequestHeader("Authorization") String authorization) { | ||
if ("token001".equals(authorization)) { | ||
Map<String, Object> userInfo = new HashMap<>(); | ||
userInfo.put("id", 1); | ||
userInfo.put("gender", 1); | ||
return userInfo; | ||
} | ||
throw new RuntimeException("小朋友,你没有登录哟!"); | ||
} | ||
|
||
@PostMapping("/user/update") | ||
public Boolean update(@RequestBody UserUpdateVO updateVO) { | ||
logger.info("[update][收到更新请求:{}]", updateVO.toString()); | ||
return true; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...ug/lab-71-idea-http-client/src/main/java/cn/iocoder/springboot/lab71/vo/UserUpdateVO.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,43 @@ | ||
package cn.iocoder.springboot.lab71.vo; | ||
|
||
/** | ||
* 用户更新 VO | ||
*/ | ||
public class UserUpdateVO { | ||
|
||
/** | ||
* 昵称 | ||
*/ | ||
private String nickname; | ||
/** | ||
* 性别 | ||
*/ | ||
private Integer gender; | ||
|
||
public String getNickname() { | ||
return nickname; | ||
} | ||
|
||
public UserUpdateVO setNickname(String nickname) { | ||
this.nickname = nickname; | ||
return this; | ||
} | ||
|
||
public Integer getGender() { | ||
return gender; | ||
} | ||
|
||
public UserUpdateVO setGender(Integer gender) { | ||
this.gender = gender; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UserUpdateVO{" + | ||
"nickname='" + nickname + '\'' + | ||
", gender=" + gender + | ||
'}'; | ||
} | ||
|
||
} |
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,18 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>labs-parent</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-71-http-debug</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>lab-71-idea-http-client</module> | ||
</modules> | ||
|
||
</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