1. 程式人生 > >Springmvc中檢視向控制器傳輸引數的一種方法

Springmvc中檢視向控制器傳輸引數的一種方法

以前在專案中檢視向控制器傳輸引數的方式一般是通過ajax傳輸,然後在控制器中一個個的獲取所傳輸的引數如

String userId=request.getParameter("userId");

今天用到一種不一樣的,不一樣之處,如果要獲取一個物件引數

public class User {

private Integer id;
private String username;
private String password;
private String account;

在檢視中表現為

<form id="loginForm">
<table  width="320" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="35">使用者名稱:</td>
    <td width="250"><input class="login_input" id="username" name="username" type="text"/></td>
  </tr>
  <tr>
    <td height="35">密 碼:</td>
    <td><input class="login_input" id="password" name="password" type="password"/></td>
  </tr>
  <tr>

點選提交時,這兩個屬性會直接繫結到前面的User物件上面

@RequestMapping("/login") 
@ResponseBody
@LogAnnotation(module="登入模組",type="登入")
public Map<String,Object> login(User user,HttpServletRequest request,HttpServletResponse response,RespModel respModel){

       在這裡可以直接使用user物件了

}

是不是方便很多呢。