0
這裏是我的jsp片段jQuery的自動完成功能無法使用Spring MVC工作
<form:form>
<form:input path = "state" id = "state"/>
</form:form>
<script>
$(document).ready(function() {
$("#state").autocomplete({
source: '${pageContext. request. contextPath}/getStatelist.htm'
});
});
</script>
這裏是一個應該返回狀態列表
@RequestMapping(value = "/getStatelist.htm", method = RequestMethod.GET, headers = "Accept=*/*")
public @ResponseBody List<String> getStateList(@RequestParam("term") String query) {
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
MasterJDBCTemplate dao =
(MasterJDBCTemplate)context.getBean("masterJDBCTemplate");
System.out.println(query);
System.out.println("Controller called");
List<String> fans = dao.getStateList(query);
return fans;
}
運行的代碼,並輸入到文本框後的控制器代碼狀態,控制器被調用,我得到正確的結果打印在控制檯上。示例運行如下所示。
g
Controller called
select state_desc from mst_state where state_desc like 'G%'
[GUJRAT, GOA]
gu
Controller called
select state_desc from mst_state where state_desc like 'GU%'
[GUJRAT]
guj
Controller called
select state_desc from mst_state where state_desc like 'GUJ%'
[GUJRAT]
但是我無法在前端看到任何東西。我錯過了什麼?可能是什麼原因 ??