惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
Recent Announcements
Recent Announcements
博客园 - 司徒正美
P
Proofpoint News Feed
博客园 - 聂微东
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
量子位
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - Franky
B
Blog RSS Feed
F
Full Disclosure
The Cloudflare Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
D
DataBreaches.Net
N
News and Events Feed by Topic
S
Secure Thoughts
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
U
Unit 42
G
Google Developers Blog
Forbes - Security
Forbes - Security
S
Schneier on Security
T
Threatpost
W
WeLiveSecurity
I
Intezer
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
Troy Hunt's Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
有赞技术团队
有赞技术团队
S
Security Affairs
Cisco Talos Blog
Cisco Talos Blog
T
Tenable Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost

博客园 - huanshare

系统架构设计师 2025年下半年 综合知识 信息系统项目管理师 2025年上半年(第2批)综合知识 AI 写长篇别靠玄学:我用 codebubby + Cursor 把《一纸洛阳》写到50章还不崩 特别好用的swagger ui 封装 微信小程序常见问题1----适合新手 依赖注入和控制反转的理解,写的太好了。 [MySQL] 实现树形的遍历(关于多级菜单栏以及多级上下部门的查询问题) Maven实战--- dependencies与dependencyManagement的区别 SSO 单点登录的实现原理 Spring boot将配置属性注入到bean类中 在spring中常被忽视的注解 @Primary spring四种依赖注入方式 Spring AOP 学习(一) 代理模式 Ajax+Spring MVC实现跨域请求(JSONP) 对JAVA的集合的理解 Iterator和ListIterator Java中finalize()用法 Spring中的设计模式 sql 在not in 子查询有null值情况下经常出现的陷阱
SpringMVC @RequestBody接收Json对象字符串
huanshare · 2016-11-22 · via 博客园 - huanshare

以前,一直以为在SpringMVC环境中,@RequestBody接收的是一个Json对象,一直在调试代码都没有成功,后来发现,其实 @RequestBody接收的是一个Json对象的字符串,而不是一个Json对象。然而在ajax请求往往传的都是Json对象,后来发现用 JSON.stringify(data)的方式就能将对象变成字符串。同时ajax请求的时候也要指定dataType: "json",contentType:"application/json" 这样就可以轻易的将一个对象或者List传到Java端,使用@RequestBody即可绑定对象或者List.

<script type="text/javascript">  
    $(document).ready(function(){  
        var saveDataAry=[];  
        var data1={"userName":"test","address":"gz"};  
        var data2={"userName":"ququ","address":"gr"};  
        saveDataAry.push(data1);  
        saveDataAry.push(data2);         
        $.ajax({ 
            type:"POST", 
            url:"user/saveUser", 
            dataType:"json",      
            contentType:"application/json",               
            data:JSON.stringify(saveData), 
            success:function(data){ 
                                       
            } 
         }); 
    });  
</script> 
  @RequestMapping(value = "saveUser", method = {RequestMethod.POST }}) 
    @ResponseBody  
    public void saveUser(@RequestBody List<User> users) { 
         userService.batchSave(users); 
    }