Update 26.1. The ‘Spring Web MVC framework’.md
parent
f67f38877a
commit
1173ca57be
|
@ -0,0 +1,28 @@
|
|||
### 26.1. Spring Web MVC框架
|
||||
|
||||
Spring Web MVC框架(通常简称为"Spring MVC")是一个富"模型,视图,控制器"的web框架。
|
||||
Spring MVC允许你创建特定的@Controller或@RestController beans来处理传入的HTTP请求。
|
||||
使用@RequestMapping注解可以将控制器中的方法映射到相应的HTTP请求。
|
||||
|
||||
示例:
|
||||
```java
|
||||
@RestController
|
||||
@RequestMapping(value="/users")
|
||||
public class MyRestController {
|
||||
|
||||
@RequestMapping(value="/{user}", method=RequestMethod.GET)
|
||||
public User getUser(@PathVariable Long user) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@RequestMapping(value="/{user}/customers", method=RequestMethod.GET)
|
||||
List<Customer> getUserCustomers(@PathVariable Long user) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@RequestMapping(value="/{user}", method=RequestMethod.DELETE)
|
||||
public User deleteUser(@PathVariable Long user) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue