【Spring学习笔记-MVC-6】SpringMVC 之@RequestBody 接收Json数组对象
1. 摘要
- 前台使用ajax技术,传递json字符串到后台;
- 后台使用Spring MVC注解@RequestBody 接受前台传递的json字符串,并返回新的json字符串到前台;
- 前台接受后台传递过来的json数据,并显示。

<%@ page language="java" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";response.setHeader("Pragma", "no-cache");response.setHeader("Cache-Control", "no-cache");response.setDateHeader("Expires", 0);%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>SpringMVC+ajax+json</title><script type="text/javascript">var basePath = "<%=basePath%>";</script><%-- <link rel="stylesheet" type="text/css" href="<%=basePath%>js/easyui/demo.css"> --%><script type="text/javascript" src="<%=basePath%>js/JQuery/jquery.min.js"></script><script type="text/javascript" src="<%=basePath%>js/test/ajaxAndJson.js"></script></head><body><div style="padding:5px 0;"><p>SpringMVC @RequestBody 接收Json数组对象</p><a href="#" class="easyui-linkbutton" onclick="loadData()" data-options="iconCls:'icon-add'">@RequestBody 接收Json数组对象</a></div></body></html>

3. 后台java代码



4. 配置
web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><!-- 从类路径下加载Spring配置文件,classpath关键字特指从类路径下加载 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- 负责启动Spring容器的监听器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 配置Spring MVC,其对应的配置文件为:servlet-name-servlet.xml, 本项目的为:spring-servlet.xml --><servlet><servlet-name>spring</servlet-name><servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>3</load-on-startup></servlet><servlet-mapping><servlet-name>spring</servlet-name><url-pattern>*.action</url-pattern></servlet-mapping></web-app>
spring-servlet.xml

applicationContext.xml

5. 结果


6. 其他
淘宝:
【Spring学习笔记-MVC-6】SpringMVC 之@RequestBody 接收Json数组对象的更多相关文章
- SpringMVC 之@RequestBody 接收Json数组对象
1. 摘要 程序流程: 前台使用ajax技术,传递json字符串到后台: 后台使用Spring MVC注解@RequestBody 接受前台传递的json字符串,并返回新的json字符串到前台: 前台 ...
- SpringMVC @RequestBody 接收Json数组对象
@RequestMapping(value="/signIn",method=RequestMethod.POST) public int saveUser(@RequestBod ...
- 【Spring学习笔记-MVC-9】SpringMVC数据格式化之日期转换@DateTimeFormat
作者:ssslinppp 1. 摘要 本文主要讲解Spring mvc数据格式化的具体步骤: 并讲解前台日期格式如何转换为java对象: 在之前的文章<[Spring学习笔记-MVC ...
- 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- 【Spring学习笔记-MVC-3】SpringMVC返回Json数据-方式1
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- 3.《Spring学习笔记-MVC》系列文章,讲解返回json数据的文章共有3篇,分别为:
转自:https://www.cnblogs.com/ssslinppp/p/4528892.html 概述 在文章:<[Spring学习笔记-MVC-3]SpringMVC返回Json数据-方 ...
- 1.《Spring学习笔记-MVC》系列文章,讲解返回json数据的文章共有3篇,分别为:
转自:https://www.cnblogs.com/ssslinppp/p/4528892.html [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://w ...
- 2.《Spring学习笔记-MVC》系列文章,讲解返回json数据的文章共有3篇,分别为:
转自:https://www.cnblogs.com/ssslinppp/p/4528892.html 个人认为,使用@ResponseBody方式来实现json数据的返回比较方便,推荐使用. 摘要 ...
- SpringMVC接收json数组对象
最近帮一个妹子解决一个需求,就是前台使用ajax传三个相同的对象,再加一个form表单对象.然后遇到各种问题,终于解决了,@RequestBody接收Json对象字符串 以前,一直以为在Spring ...
随机推荐
- SQL Server 调优系列玩转篇一(如何利用查询提示(Hint)引导语句运行)
前言 前面几篇我们分析了关于SQL Server关于性能调优的一系列内容,我把它分为两个模块. 第一个模块注重基础内容的掌握,共分7篇文章完成,内容涵盖一系列基础运算算法,详细分析了如何查看执行计划. ...
- bzoj3065
题解: 替罪羊树 (讲道理昨天讲课我一点都听不懂) alpha取到0.75比较好(当然啦可能其他的更好) 每当不满足条件的时候就重构 代码: #include<bits/stdc++.h> ...
- Microsoft Jet 数据库引擎 SQL 和 ANSI SQL 的比较
http://westlife063.blog.163.com/blog/static/129942096201052591210384/ Microsoft Jet 数据库引擎 SQL 和 AN ...
- Windows 下python的tab自动补全
方法一:安装一个ipython就OK啦,而且关键字还能高亮显示呢 一.打开cmd,输入pip3 install ipython联网安装 二.安装成功后,cmd里运行ipython,成功啦. 方法二:写 ...
- Python+Requests接口测试教程(2):requests
开讲前,告诉大家requests有他自己的官方文档:http://cn.python-requests.org/zh_CN/latest/ 2.1 发get请求 前言requests模块,也就是老污龟 ...
- 如何使用firebug
什么是Firebug 从事了数年的Web开发工作,越来越觉得现在对WEB开发有了更高的要求.要写出漂亮的HTML代码:要编写精致的CSS样式表展示每个页面模块:要调试javascript给页面增加一些 ...
- eclipse ubuntu error
eclipse cdt :symbol cout can not be solved Preferences -> C/C++ -> Indexer -> Use active bu ...
- 允许发生http请求
- 简单介绍Spring的ContextLoaderListener
在开发Spring的Web项目中,通常我们都会在web.xml中配置一个Spring的核心监听器,就是把Spring的IOC容器纳入Servlet容器中,配置如下: <listener> ...
- BZOJ3879: SvT【后缀数组+单调栈】
Description (我并不想告诉你题目名字是什么鬼) 有一个长度为n的仅包含小写字母的字符串S,下标范围为[1,n]. 现在有若干组询问,对于每一个询问,我们给出若干个后缀(以其在S中出现的起始 ...