在controller中:
@RequestMapping("/type")
public String getType(HttpServletRequest req, HttpServletResponse rsp)
throws IOException {
req.setCharacterEncoding("utf-8");
rsp.setCharacterEncoding("utf-8");
System.out.println("进入gettype......");
List<Book> listType = libraryService.getBookType();
PrintWriter out=rsp.getWriter();
out.print(JSON.toJSONString(listType));
return null;
}
页面上:
<select id="sel_menu3" ></select>
js函数:
function cc(){
$.post("<%=path%>/home/type",

这篇博客介绍了如何通过控制器获取数据库中的Book类型列表,然后利用JS(jQuery)将这些数据动态添加到HTML的select下拉框中。在Java后端,使用@RequestMapping处理请求并返回JSON数据。在前端,通过$.post发送异步请求,解析响应的JSON数据,并遍历填充到<select>元素中。
最低0.47元/天 解锁文章
1068

被折叠的 条评论
为什么被折叠?



