1

嗨,我正在使用自动完成功能在 spring 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>
4

1 回答 1

0

我不确定“不过滤”是什么意思,但您没有在控制器端使用查询参数。例如,它应该如下所示:

@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;
}
于 2014-06-25T11:09:38.540 回答