spring mvc中有一个注解:@ResponseBody,把这个注解放到ajax请求对应的@RequestMapping(xxx)方法上,在方法体内部,把要返回的json赋给一个String类型的变量,然后return这个变量即可,例子如下:

        @ResponseBody
@RequestMapping("/show")
public String show(Map<String,Object> map,String username){
System.out.println("----enter show method");
RepositoryService rs = processEngine.getRepositoryService();
ExecutionService es = processEngine.getExecutionService();
TaskService ts = processEngine.getTaskService();
List<ProcessDefinition> liststemp = rs.createProcessDefinitionQuery().list();
List<PD> lists=toJsonList.processDefine2PD(liststemp)
Gson gson=new Gson();
String str=gson.toJson(lists); return str;
@ResponseBody
@RequestMapping("/show")
public String show(Map<String,Object> map,String username){
System.out.println("----enter show method");
RepositoryService rs = processEngine.getRepositoryService();
ExecutionService es = processEngine.getExecutionService();
TaskService ts = processEngine.getTaskService();
List<ProcessDefinition> liststemp = rs.createProcessDefinitionQuery().list();
List<PD> lists=toJsonList.processDefine2PD(liststemp)
Gson gson=new Gson();
String str=gson.toJson(lists); return str;

  

 

spring mvc后台如何处理ajax的请求,并返回json的更多相关文章

  1. jquery的ajax异步请求接收返回json数据

    http://www.jb51.net/article/51122.htm jquery的ajax异步请求接收返回json数据方法设置简单,一个是服务器处理程序是返回json数据,另一种就是ajax发 ...

  2. 解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容

    解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容 解决方案 在 Web.xml文件中 加入以下代码 <!--解决ajax Put与Del请求无法接收到传输的内容-- ...

  3. spring mvc(2):请求地址映射(@RequestMapping)

    @RequestMapping 参数说明 value定义处理方法的请求的 URL 地址.method定义处理方法的 http method 类型,如 GET.POST 等.params定义请求的 UR ...

  4. Query通过Ajax向PHP服务端发送请求并返回JSON数据

    Query通过Ajax向PHP服务端发送请求并返回JSON数据 服务端PHP读取MYSQL数据,并转换成JSON数据,传递给前端Javascript,并操作JSON数据.本文将通过实例演示了jQuer ...

  5. Spring Security 前后端分离登录,非法请求直接返回 JSON

    hello 各位小伙伴,国庆节终于过完啦,松哥也回来啦,今天开始咱们继续发干货! 关于 Spring Security,松哥之前发过多篇文章和大家聊聊这个安全框架的使用: 手把手带你入门 Spring ...

  6. 七:Spring Security 前后端分离登录,非法请求直接返回 JSON

    Spring Security 前后端分离登录,非法请求直接返回 JSON 解决方案 在 Spring Security 中未获认证的请求默认会重定向到登录页,但是在前后端分离的登录中,这个默认行为则 ...

  7. ajax数据请求2(json格式)

    ajax数据请求2(json格式) <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  8. hibernate+spring mvc,解决hibernate对象懒加载,json序列化失败

    在使用spring MVC时,@ResponseBody 注解的方法返回一个有懒加载对象的时候出现了异常,以登录为例: @RequestMapping("login") @Resp ...

  9. 根据传入url请求,返回json字符串

    /** * 根据传入url请求,返回json字符串 * @param url * @return * @throws UnsupportedEncodingException */ public st ...

随机推荐

  1. function方法控制是否隐藏部分内容

    $(document).ready(function() { $('input[type=radio][name=IE]').change(function() { if (this.value == ...

  2. ubuntu部署jenkins

    https://www.cnblogs.com/lozz/p/9962316.html 1.安装 wget -q -O - https://pkg.jenkins.io/debian/jenkins- ...

  3. iperf——网络性能测试工具

    一.前言 工作中遇到需要测试Linux服务器网卡占用率的场景,查阅资料后,发现iperf是一款合适的网络测速工具. 下面讲解一下如何使用iperf做网络性能测试. 二.基础知识 先补充一些基础知识: ...

  4. Spring依赖注入:基于xml配置

    基础接口 BeanFactory.ApplicationContext. BeanFactory用于创建并管理.获取各种类的对象. ApplicationContext从BeanFactory派生而来 ...

  5. Python3 ord() 函数

    Python3 ord() 函数  Python3 内置函数 描述 ord() 函数是 chr() 函数(对于 8 位的 ASCII 字符串)的配对函数,它以一个字符串(Unicode 字符)作为参数 ...

  6. Centos7 安装MySQL8.0.15

    1.删除原有的mariadb,不然mysql装不进去 mariadb-libs-5.5.52-1.el7.x86_64 rpm -qa|grep mariadb rpm -e --nodeps mar ...

  7. rpmdb open failed的解决办法

      错误信息如下:    “错误:无法从 /var/lib/rpm 打开软件包数据库      CRITICAL:yum.main:       Error: rpmdb open failed”   ...

  8. SNP问题大集锦

    SNP问题大集锦 [2017-01-19]       最近小编对基因检测很感兴趣,也跟风去测了一下,这一测不要紧,吓得小编几天没睡着觉,这不,检测报告上称小编的减肥能力弱,虽然小编一家都是胖子,唯有 ...

  9. url地址 参数 带 参数 注意事项 , chain , redirect , redirectAction

    当 url  地址中含有  参数 时 ,若参数值是一个 含有 参数的 地址时 , 应警惕 ,如 index/goIndex!login?backUrl=/shop/goShop!go?a1=1& ...

  10. 使用Jsoup获取网页内容超时设置

    使用Jsoup获取网页内容超时设置 最近使用Jsoup来抓取网页,并对网页进行解析,发现很好用.在抓取过程中遇到一个问题,有些页面总是报Timeout异常,开始想是不是被抓取网站对IP进行了限制,后来 ...