首页 > 其他分享 >passing JSON data to a Spring MVC controller

passing JSON data to a Spring MVC controller

时间:2023-03-22 15:07:27浏览次数:42  
标签:jsonString jackson Spring JSON 1.9 RequestBody Person controller false


Add the following dependencies

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-mapper-asl</artifactId>

<version>1.9.7</version>

</dependency>

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-core-asl</artifactId>

<version>1.9.7</version>

</dependency>

add request as follows

$.ajax({ 

url:urlName,

type:"POST",

contentType: "application/json; charset=utf-8",

data: jsonString, //Stringified Json Object

async: false, //Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation

cache: false, //This will force requested pages not to be cached by the browser

processData:false, //To avoid making query String instead of JSON

success: function(resposeJsonObject){

}});

CONTROLLER SIDE

@RequestMapping(value = urlPattern , method = RequestMethod.POST)

public @ResponseBody Person save(@RequestBody Person jsonString) {

Person person=personService.savedata(jsonString);

return person;

}

@RequestBody -Covert Json object to java

@ResponseBody-convert Java object to json

标签:jsonString,jackson,Spring,JSON,1.9,RequestBody,Person,controller,false
From: https://blog.51cto.com/u_2650279/6142617

相关文章

  • spring MVC 中json格式数据发送与接收
    在web程序开发中,前端和服务器数据的传输方式常用的有两种,一种是以表单的形式提交,此时可以利用jquery的serialize()方法将表单内容转为a=1&b=2&c=3&d=4&e=5这样的格式传输过......
  • spring mvc 3 国际化(下)——简单自定义操作
    根据域名来判断用户语言:1.定义一个对象;SelfLocaleResolver1.publicclassSelfLocaleResolverextends2.@Override3.public4.if("127.0.0.1".equalsIgnoreCase(requ......
  • springboot动态修改properties文件
    importjava.io.BufferedWriter;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.OutputStreamWriter;......
  • kube-controller-manager启动失败
    报错信息:Error:failedtostartcontainer"kube-controller-manager":Errorresponsefromdaemon:OCIruntimecreatefailed:container_linux.go:338:creatingne......
  • 不用spring,可以吗?
    摘自:https://www.zhihu.com/question/537894826Java开发不用Spring生态有前途吗?比如在某些大厂自己封装好的框架直接用,感觉没啥提升新增:做后端web开发。这套框架......
  • daemon.json 常用配置项
    {"registry-mirrors":["https://fv50tv30.mirror.aliyuncs.com","https://reg-mirror.qiniu.com"],"dns":["114.114.114.114","8.8.8.8"],"dat......
  • SMU Spring 2023 Trial Contest Round 1(6/8)
    SMUSpring2023TrialContestRound1(6/8)A.PrependandAppendPrependandAppend只需考虑给定字符串两端是否符合10或01即可,双指针从两端模拟即可。#include<iost......
  • SpringMVC配置文件位置
    [size=large][color=red]在工程内:[/color][/size]<context:property-placeholderlocation="classpath:/site.properties"/>[size=large][color=red......
  • Spring MVC视图解析器:配置多个视图解析器的优先级
    [color=red]问题[/color]在SpringMVC应用程序中,我们经常需要应用一些视图解析器策略来解析视图名称。例如,联合使用三个视图解析器:InternalResourceViewResolver、Resourc......
  • Spring MVC拦截器+注解方式实现防止表单重复提交
    原理:在新建页面中Session保存token随机码,当保存时验证,通过后删除,当再次点击保存时由于服务器端的Session中已经不存在了,所有无法验证通过。注,如果是集群的方式,则需要将tok......