Copyright © 2022-2024 aizws.net · 网站版本: v1.2.6·内部版本: v1.23.3·
页面加载耗时 0.00 毫秒·物理内存 74.2MB ·虚拟内存 1303.8MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
url格式:http://localhost/adduser
bean:
// 注意这里类的属性名要和post请求携带的参数名一样 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来封装接收的参数:
@PostMapping("/addUser") public String addUser(@RequestBody UserModel user) { System.out.println("username is:"+user.getUsername()); System.out.println("password is:"+user.getPassword()); return "username is:"+username + " " + "password is:"+password; }
url格式:http://localhost/adduser
@PostMapping("/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
bean:
// 注意这里类的属性名要和post请求携带的参数名一样 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来封装接收的参数:
@PostMapping("/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; }
1、作用@RequestParam:将请求参数绑定到控制器的方法参数。 2、语法@RequestParam(value=”参数名”, r ...