这是我的jsp片段
<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]
但是我在前端看不到任何东西。我错过了什么?可能是什么原因 ??