SpringMVC如何用实体对象接收参数
1个回答
2018-07-04 · 国内最优秀java资源共享平台
关注
展开全部
1.jsp页面 -->提交的表单
<form action="abc" method="post">
姓名<input type="text" name="username" ><br>
密码<input type="text" name="password" ><br>
手机号<input type="text" name="phone" ><br>
<button type="submit">点击测试</button>
</form>
2.实体类 -->pojo (User)
public class User {
private String username;
private String password;
private String phone;
。。。。省略getter/setter方法
3.接收controller --> HelloController
@Controller
public class HelloController {
@RequestMapping("/itemList")
public ModelAndView itemList(User user){
System.out.println(user);
ModelAndView ma=new ModelAndView();
ma.setViewName("/hello.jsp");
return ma;
}
<form action="abc" method="post">
姓名<input type="text" name="username" ><br>
密码<input type="text" name="password" ><br>
手机号<input type="text" name="phone" ><br>
<button type="submit">点击测试</button>
</form>
2.实体类 -->pojo (User)
public class User {
private String username;
private String password;
private String phone;
。。。。省略getter/setter方法
3.接收controller --> HelloController
@Controller
public class HelloController {
@RequestMapping("/itemList")
public ModelAndView itemList(User user){
System.out.println(user);
ModelAndView ma=new ModelAndView();
ma.setViewName("/hello.jsp");
return ma;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询