Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 121.1MB ·虚拟内存 1372.6MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
url格式:http://localhost/adduser?username=aizws&password=88888
@GetMapping("/adduser")
public String addUser(@RequestParam("username") String username,@RequestParam("password") String password) {
System.out.println("username is:"+username);
System.out.println("password is:"+password);
return "username is:"+username + " " + "password is:"+password;
}
url格式:http://localhost/adduser?username=aizws&password=88888
// 注意方法中的参数名要与url中携带的参数名一样
@RequestMapping("/adduser")
public String addUser(String username,String password) {
System.out.println("username is:"+username);
System.out.println("password is:"+password);
return "username is:"+username + " " + "password is:"+password;
}
url格式:http://localhost/adduser?username=aizws&password=88888
@RequestMapping("/adduser")
public String addUser(HttpServletRequest request) {
String username=request.getParameter("username");
String password=request.getParameter("password");
System.out.println("username is:"+username);
System.out.println("password is:"+password);
return "username is:"+username + " " + "password is:"+password;
}
url格式:http://localhost/adduser?username=aizws&password=88888
bean:
// 注意这里类的属性名要和url请求携带的参数名一样
public class UserModel {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
用这个bean来封装接收的参数:
@RequestMapping("/adduser")
public String addUser(UserModel user) {
System.out.println("username is:"+user.getUsername());
System.out.println("password is:"+user.getPassword());
return "username is:"+username + " " + "password is:"+password;
}
Spring Boot 通过 @PathVariable 注解获取 Url 路径参数。我们可以将 URL 中占位符参数绑定到控制器处理方法的参数:1. 在 @GetMapping 或者 @R ...