2017-08-04 40 views
0

這裏是我的searchVO如何按表單搜索關鍵字並獲取價值?

public class SearchVO { 

    String keyword="default"; 

    public String getKeyword() { 
     return keyword; 
    } 

    public void setKeyword(String keyword) { 
     this.keyword = keyword; 
    } 

} 

我想設置的SearchVO值每次我按一下按鈕。

<div class="wrap bordWrap"> 

     <form commandName="SearchVO" id="appList" name="appList" 
      action="/index2.do" method="post"> 

    First name: <input type="text" name="fname"> 
      <br> 
    Last name: <input type="text" name="lname"> 
      <br> 


      <td colspan="5"><input type="text" class="appNameID" title="" 
       value="${SearchVO.keyword} " name="searchKeyword" placeholder="ID 또는 앱 이름을 입력하세요." /></td> 

      <p> 
       <button value="Search" onclick="formSubmit()">검색</button> 
      </p> 

     </form> 





    </div> 

是有可能我剛纔設置的commnadName爲searchVo並設置搜索關鍵字?

和我的問題是我應該從控制器獲得價值嗎?'

@RequestMapping("/index2.do") 
public String list(ModelMap model,HttpServletRequest request, 
     @ModelAttribute("SearchVo")SearchVO searchVo){ 

    System.out.println("index2"); 
    System.out.println(searchVo.getKeyword()); 
    System.out.println(request.getAttribute("searchKeyword")); 


    return "index"; 
} 

回答

0

你只需要改變searchKeyword關鍵字在HTML中SearchVO關鍵字要匹配的屬性名稱。這樣你就可以輕鬆掌握控制器。

更改以下字段名稱如下。

<td colspan="5"><input type="text" class="appNameID" title="" 
         value="${SearchVO.keyword} " name="keyword" placeholder="ID 또는 앱 이름을 입력하세요." /></td>