mirror of
https://gitee.com/coder-xiaomo/java-note
synced 2025-09-06 20:01:39 +08:00
3
This commit is contained in:
BIN
张博凯的Java学习笔记.assets/image-20220120170419338.png
Normal file
BIN
张博凯的Java学习笔记.assets/image-20220120170419338.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
张博凯的Java学习笔记.assets/image-20220120170449972.png
Normal file
BIN
张博凯的Java学习笔记.assets/image-20220120170449972.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
@@ -4182,6 +4182,10 @@ src/main/resources/spring-servlet.xml
|
|||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>springmvc</servlet-name>
|
<servlet-name>springmvc</servlet-name>
|
||||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
|
<init-param> <!-- 加载SpringMVC的配置文件 -->
|
||||||
|
<param-name>contextConfigLocation</param-name>
|
||||||
|
<param-value>classpath:spring-servlet.xml</param-value>
|
||||||
|
</init-param>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>springmvc</servlet-name>
|
<servlet-name>springmvc</servlet-name>
|
||||||
@@ -4219,9 +4223,45 @@ public class UserController {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###### 在控制器类中定义处理请求的方法
|
||||||
|
|
||||||
|
> 在一个控制器类中可以定义多个方法处理不同的请求
|
||||||
|
>
|
||||||
|
> 在每个方法上添加 `@RequestMapping("/login")` 用于声明当前方法的请求url地址
|
||||||
|
|
||||||
|
```java
|
||||||
|
package org.example.web;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@RequestMapping("/add")
|
||||||
|
public void addUser(){
|
||||||
|
System.out.println("增加");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/select")
|
||||||
|
public void viewUser(){
|
||||||
|
System.out.println("查询");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
添加mvc命名空间
|
|
||||||
|
##### 启动
|
||||||
|
|
||||||
|
浏览器访问:http://localhost:8080/user/add
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
服务端成功输出信息
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user