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
Nov 15, 2019
1 parent
1d03c0d
commit d14162e
Showing
24 changed files
with
948 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,15 @@ | ||
<?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-22</artifactId> | ||
|
||
|
||
</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,31 @@ | ||
<?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.1.3.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-springmvc-23-01</artifactId> | ||
|
||
<dependencies> | ||
<!-- 实现对 Spring MVC 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 方便等会写单元测试 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
.../lab-springmvc-23-01/src/main/java/cn/iocoder/springboot/lab21/springmvc/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.lab21.springmvc; | ||
|
||
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); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...-23-01/src/main/java/cn/iocoder/springboot/lab21/springmvc/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,91 @@ | ||
package cn.iocoder.springboot.lab21.springmvc.controller; | ||
|
||
import cn.iocoder.springboot.lab21.springmvc.dto.UserAddDTO; | ||
import cn.iocoder.springboot.lab21.springmvc.dto.UserUpdateDTO; | ||
import cn.iocoder.springboot.lab21.springmvc.vo.UserVO; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* 用户 Controller | ||
*/ | ||
@RestController | ||
@RequestMapping("/users") | ||
public class UserController { | ||
|
||
/** | ||
* 查询用户列表 | ||
* | ||
* @return 用户列表 | ||
*/ | ||
@GetMapping("") | ||
public List<UserVO> list() { | ||
// 查询列表 | ||
List<UserVO> result = new ArrayList<>(); | ||
result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); | ||
result.add(new UserVO().setId(2).setUsername("woshiyutou")); | ||
result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); | ||
// 返回列表 | ||
return result; | ||
} | ||
|
||
/** | ||
* 获得指定用户编号的用户 | ||
* | ||
* @param id 用户编号 | ||
* @return 用户 | ||
*/ | ||
@GetMapping("/{id}") | ||
public UserVO get(@PathVariable("id") Integer id) { | ||
// 查询并返回用户 | ||
return new UserVO().setId(id).setUsername("username:" + id); | ||
} | ||
|
||
/** | ||
* 添加用户 | ||
* | ||
* @param addDTO 添加用户信息 DTO | ||
* @return 添加成功的用户编号 | ||
*/ | ||
@PostMapping("") | ||
public Integer add(UserAddDTO addDTO) { | ||
// 插入用户记录,返回编号 | ||
Integer returnId = 1; | ||
// 返回用户编号 | ||
return returnId; | ||
} | ||
|
||
/** | ||
* 更新指定用户编号的用户 | ||
* | ||
* @param id 用户编号 | ||
* @param updateDTO 更新用户信息 DTO | ||
* @return 是否修改成功 | ||
*/ | ||
@PutMapping("/{id}") | ||
public Boolean update(@PathVariable("id") Integer id, UserUpdateDTO updateDTO) { | ||
// 将 id 设置到 updateDTO 中 | ||
updateDTO.setId(id); | ||
// 更新用户记录 | ||
Boolean success = true; | ||
// 返回更新是否成功 | ||
return success; | ||
} | ||
|
||
/** | ||
* 删除指定用户编号的用户 | ||
* | ||
* @param id 用户编号 | ||
* @return 是否删除成功 | ||
*/ | ||
@DeleteMapping("/{id}") | ||
public Boolean delete(@PathVariable("id") Integer id) { | ||
// 删除用户记录 | ||
Boolean success = false; | ||
// 返回是否更新成功 | ||
return success; | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
...23-01/src/main/java/cn/iocoder/springboot/lab21/springmvc/controller/UserController2.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,89 @@ | ||
package cn.iocoder.springboot.lab21.springmvc.controller; | ||
|
||
import cn.iocoder.springboot.lab21.springmvc.dto.UserAddDTO; | ||
import cn.iocoder.springboot.lab21.springmvc.dto.UserUpdateDTO; | ||
import cn.iocoder.springboot.lab21.springmvc.vo.UserVO; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* 用户2 Controller | ||
*/ | ||
@RestController | ||
@RequestMapping("/users2") | ||
public class UserController2 { | ||
|
||
/** | ||
* 查询用户列表 | ||
* | ||
* @return 用户列表 | ||
*/ | ||
@GetMapping("/list") // URL 修改成 /list | ||
public List<UserVO> list() { | ||
// 查询列表 | ||
List<UserVO> result = new ArrayList<>(); | ||
result.add(new UserVO().setId(1).setUsername("yudaoyuanma")); | ||
result.add(new UserVO().setId(2).setUsername("woshiyutou")); | ||
result.add(new UserVO().setId(3).setUsername("chifanshuijiao")); | ||
// 返回列表 | ||
return result; | ||
} | ||
|
||
/** | ||
* 获得指定用户编号的用户 | ||
* | ||
* @param id 用户编号 | ||
* @return 用户 | ||
*/ | ||
@GetMapping("/get") // URL 修改成 /get | ||
public UserVO get(@RequestParam("id") Integer id) { | ||
// 查询并返回用户 | ||
return new UserVO().setId(id).setUsername(UUID.randomUUID().toString()); | ||
} | ||
|
||
/** | ||
* 添加用户 | ||
* | ||
* @param addDTO 添加用户信息 DTO | ||
* @return 添加成功的用户编号 | ||
*/ | ||
@PostMapping("add") // URL 修改成 /add | ||
public Integer add(UserAddDTO addDTO) { | ||
// 插入用户记录,返回编号 | ||
Integer returnId = UUID.randomUUID().hashCode(); | ||
// 返回用户编号 | ||
return returnId; | ||
} | ||
|
||
/** | ||
* 更新指定用户编号的用户 | ||
* | ||
* @param updateDTO 更新用户信息 DTO | ||
* @return 是否修改成功 | ||
*/ | ||
@PostMapping("/update") // URL 修改成 /update ,RequestMethod 改成 POST | ||
public Boolean update(UserUpdateDTO updateDTO) { | ||
// 更新用户记录 | ||
Boolean success = true; | ||
// 返回更新是否成功 | ||
return success; | ||
} | ||
|
||
/** | ||
* 删除指定用户编号的用户 | ||
* | ||
* @param id 用户编号 | ||
* @return 是否删除成功 | ||
*/ | ||
@DeleteMapping("/delete") // URL 修改成 /delete ,RequestMethod 改成 DELETE | ||
public Boolean delete(@RequestParam("id") Integer id) { | ||
// 删除用户记录 | ||
Boolean success = false; | ||
// 返回是否更新成功 | ||
return success; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...b-springmvc-23-01/src/main/java/cn/iocoder/springboot/lab21/springmvc/dto/UserAddDTO.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,35 @@ | ||
package cn.iocoder.springboot.lab21.springmvc.dto; | ||
|
||
/** | ||
* 用户添加 DTO | ||
*/ | ||
public class UserAddDTO { | ||
|
||
/** | ||
* 账号 | ||
*/ | ||
private String username; | ||
/** | ||
* 密码 | ||
*/ | ||
private String password; | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public UserAddDTO setUsername(String username) { | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public UserAddDTO setPassword(String password) { | ||
this.password = password; | ||
return this; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...pringmvc-23-01/src/main/java/cn/iocoder/springboot/lab21/springmvc/dto/UserUpdateDTO.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,45 @@ | ||
package cn.iocoder.springboot.lab21.springmvc.dto; | ||
|
||
public class UserUpdateDTO { | ||
|
||
/** | ||
* 编号 | ||
*/ | ||
private Integer id; | ||
/** | ||
* 账号 | ||
*/ | ||
private String username; | ||
/** | ||
* 密码 | ||
*/ | ||
private String password; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public UserUpdateDTO setId(Integer id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public UserUpdateDTO setUsername(String username) { | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public UserUpdateDTO setPassword(String password) { | ||
this.password = password; | ||
return this; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...23/lab-springmvc-23-01/src/main/java/cn/iocoder/springboot/lab21/springmvc/vo/UserVO.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,35 @@ | ||
package cn.iocoder.springboot.lab21.springmvc.vo; | ||
|
||
/** | ||
* 用户 VO | ||
*/ | ||
public class UserVO { | ||
|
||
/** | ||
* 编号 | ||
*/ | ||
private Integer id; | ||
/** | ||
* 账号 | ||
*/ | ||
private String username; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public UserVO setId(Integer id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public UserVO setUsername(String username) { | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
} |
Oops, something went wrong.