spring mvc with jquery autocomplete返回列表但不过滤

时间:2013-10-12 07:09:03

标签: spring-mvc jquery-autocomplete

嗨我正在挣扎着自动完成的春天mvc,它会去方法并返回列表,但不会在自动完成文本框中过滤,请任何身体帮助我,而且我的代码也是如此。

我也尝试过json和jquery。

 in jsp
    ---------
    $(function() {$( "#clientName" ).autocomplete({
                source: '${pageContext. request. contextPath}/getClientNames.htm'
                    });
    <label for="clientName">Search Client: </label>
                <input id="clientName" ></input>

    in spring method
    ----------------
    @RequestMapping(value = "/getClientNames",
                 method = RequestMethod.GET,
                 headers="Accept=application/json")
       public @ResponseBody List<String> getTechList(@RequestParam("term") String query,HttpServletResponse response) {
       // List<String> countryList = dummyDB.getTechList(query);
             //response.setStatus(HttpServletResponse.SC_OK);
             List<String> clientList=new ArrayList<String>();
             clientList.add("Balu");
             clientList.add("Bala");
             clientList.add("Boss");
       return clientList;
       }

spring configuration file
-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:annotation-config/>
    <context:component-scan base-package="app.com.db.controller" />
<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean> 
<bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>
</beans>

1 个答案:

答案 0 :(得分:0)

我不确定你是什么意思&#34;不过滤&#34;但是你不能在你的控制器端使用查询参数。例如,它应该看起来像:

@RequestMapping(value = "/getClientNames", method = RequestMethod.GET, headers="Accept=application/json")
public @ResponseBody List<String> getTechList(@RequestParam("term") String query,HttpServletResponse response) {
   List<String> clientList=new ArrayList<String>();
   clientList.add("Balu");
   clientList.add("Bala");
   clientList.add("Boss");

   List<String> result = new ArrayList<String>();
   for (String client : clientList) {
       if (client.contains(query)) {
         result.add(client);
       }
   }

   return result;
}