2014-05-20 68 views
0
* SearchVo 
public class SearchVo { 
    private int startRow; 
    private int rowBlockCount = 20; 

    private String firstName; 
    private String lastName; 
} 


* Controller  
@Controller 
public class EmpController { 

    @RequestMapping(value = "/list.do") 
    public String list(
     @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, 
     @ModelAttribute("search") SearchVo search, 
     ModelMap modelMap 
    ) 
    { 
     Map<String, Object> map = empService.list(pageNum, search); 

     modelMap.addAttribute("search", search); 
     modelMap.addAttribute("list", map.get("list")); 
     modelMap.addAttribute("pageUtil", map.get("pageUtil")); 

     return "list"; 
    } 
} 


* jsp 
<form:form modelAttribute="search" action="list.do"> 
    <form:input path="firstName" /> 
    <form:input path="secondName" /> 
    <a href="javascript:search();">search</a> 

    LIST............................ 

    <div class="pageNavi"> 
     <span> 
      <strong title="current page">1</strong> 
      <a href="javascript:act.move('2');">2</a> 
      <a href="javascript:act.move('3');">3</a> 
      <a href="javascript:act.move('4');">4</a> 
      <a href="javascript:act.move('5');">5</a> 
     </span> 
    </div> 

</form:form> 

它工作正常。如何區分使用彈簧窗體標籤(Spring MVC)的分頁和搜索

我有一個問題。 當我輸入「michael」到名字輸入框後, 如果點擊搜索按鈕,它可以搜索「mechael」。

但 後,我鍵入「邁克爾」爲FirstName輸入框, 如果點擊頁面移動按鈕,它的作品不僅移動頁面,但也搜索「mechael」。 我只想移動頁面。

With Spring Form Tag,How to correct this?

回答

0

我想創建一個私有字段來對運行檢查,像下面

@Controller 
public class EmpController 
{ 
    private String searchCheck; 

    @RequestMapping(value = "/list.do") 
    public String list(@RequestParam(value = "pageNum", defaultValue = "1") intpageNum, @ModelAttribute("search") SearchVo search, ModelMap modelMap) 
    { 
     if (searchCheck.equals(search) 
     { 
      //search term the same must be move page 
     } 
     else 
     { 
       //new search word 
       searchCheck = search; 
     } 

     return "list"; 
    } 
}