spring mvc json ajax jquery
来源:互联网 发布:js when done 编辑:程序博客网 时间:2024/06/02 18:57
1.前台页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>论坛版块</title><style type="text/css"> h1{ color:red; text-align: center; }</style><script type="text/javascript" src="../resources/js/jquery.js"></script></head><% cn.springmvc.model.User user = (cn.springmvc.model.User)session.getAttribute("user");<strong>String path = this.getServletContext().getContextPath();</strong>%><script type="text/javascript">$(document).ready(function(){ $("a[name='showTopic']").click(function(){var boardId = this.id;boardId = boardId.substring(10,boardId.length);<strong>$.ajax({</strong>type:'GET',<strong>contentType:'application/json',</strong>url:'../topics/mainTopic.html',<strong>dataType:'json',</strong>data:{ id: boardId },success:function(data){<strong>if (data&&data.success=="true"){</strong> $('#topic_ls_'+boardId).html("共"+data.total+"条数据。<br/>"); <strong> $.each(data.data,function(i, item){</strong> $('#topic_ls_'+boardId).append( "<a href='../posts/mainPost.html?id="+boardId+"'>名称:" + item.topicTitle+"</a> | 创建者:"+item.userId+" | 创建时间:"+item.createTime+"<br/>"); }); } },error:function(){alert("error");}}) })});</script><body><h1>版块列表</h1><div id="showTopic12" ></div> <c:forEach items="${boards }" var="board"> ${board.boardId }--<a id="showTopic_${board.boardId }" name="showTopic" href="javascript:void(0);">${board.boardName }</a>--${board.boardDesc }--${board.topicNum }<br/> <div id="topic_ls_${board.boardId }">${board.boardId }</div> </c:forEach></body></html>
2.java文件
@Controller@RequestMapping("/posts")public class PostController {@Autowiredprivate PostService postService;@RequestMapping(value = "/mainPost", method = RequestMethod.GET)public String getPostList(String id, Model model) {List<Post> mainPosts = postService.getMainPostListById(id);model.addAttribute("mainPosts", mainPosts);return "post/post_list";}@RequestMapping(value = "/Posts", method = RequestMethod.GET)<strong>@ResponseBody</strong>public <strong>Map<String, Object></strong> getPostList(String id) {List<Post> posts = postService.getPostListById(id);Map<String, Object> modelMap = new HashMap<String, Object>();<strong>modelMap.put("total", posts.size());modelMap.put("data", posts);modelMap.put("success", "true");</strong>return modelMap;}}
jackson-core-asl-1.9.12.jar
jackson-mapper-asl-1.9.12.jar
4.配置文件
<mvc:annotation-driven /> <!-- 支持spring3.0新的mvc注解 -->
<bean id="jacksonMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
0 0
- spring mvc json ajax jquery
- spring-mvc+ajax+json
- Spring MVC Ajax Json
- Spring mvc +jquery ajax+json的异步实例
- Spring MVC Controller与jquery ajax请求处理json
- Spring MVC Controller与jquery ajax请求处理json
- spring mvc 与 jquery ajax
- spring mvc 与 jquery ajax
- Spring MVC Ajax and JQuery
- Spring MVC Ajax and JQuery
- spring mvc 与 jquery ajax
- ajax+json+jquery第一个mvc例子
- jQuery Ajax JSON数据方式接收Spring MVC Map方式传值举例
- Spring mvc 用ajax传输json数据
- Spring MVC、Ajax和JSON的交互
- ajax json list spring mvc接收
- Spring MVC中ajax返回json数据
- spring mvc ajax 请求返回json数据
- 大型网站架构改进历程:存储的瓶颈(中)
- iphone开发之深入浅出(2) - ARC 之@property使用
- c/c++ error:在GetAdaptersInfo循环中使用strcat时,忘记清空strcat导致 内存溢出 异常
- Java之美[从菜鸟到高手演变]之设计模式二
- 百度地图画多边形并保存位置
- spring mvc json ajax jquery
- ios 点击UITextfield不让键盘弹出,并且弹出UIPicker的方法
- 查看.o, .obj文件符号列表,强大的nm命令
- 大型网站架构改进历程:存储的瓶颈(下)
- 从二本到名校 — 一个二本生的蜕变之旅
- Swift游戏开发之俄罗斯方块:No.4 滴答作响的时钟机制
- Android的内存泄漏和调试
- QR码生成原理(一)
- Java之美[从菜鸟到高手演变]之设计模式三