spring mvc后台如何处理ajax的请求,并返回json
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的更多相关文章
- jquery的ajax异步请求接收返回json数据
http://www.jb51.net/article/51122.htm jquery的ajax异步请求接收返回json数据方法设置简单,一个是服务器处理程序是返回json数据,另一种就是ajax发 ...
- 解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容
解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容 解决方案 在 Web.xml文件中 加入以下代码 <!--解决ajax Put与Del请求无法接收到传输的内容-- ...
- spring mvc(2):请求地址映射(@RequestMapping)
@RequestMapping 参数说明 value定义处理方法的请求的 URL 地址.method定义处理方法的 http method 类型,如 GET.POST 等.params定义请求的 UR ...
- Query通过Ajax向PHP服务端发送请求并返回JSON数据
Query通过Ajax向PHP服务端发送请求并返回JSON数据 服务端PHP读取MYSQL数据,并转换成JSON数据,传递给前端Javascript,并操作JSON数据.本文将通过实例演示了jQuer ...
- Spring Security 前后端分离登录,非法请求直接返回 JSON
hello 各位小伙伴,国庆节终于过完啦,松哥也回来啦,今天开始咱们继续发干货! 关于 Spring Security,松哥之前发过多篇文章和大家聊聊这个安全框架的使用: 手把手带你入门 Spring ...
- 七:Spring Security 前后端分离登录,非法请求直接返回 JSON
Spring Security 前后端分离登录,非法请求直接返回 JSON 解决方案 在 Spring Security 中未获认证的请求默认会重定向到登录页,但是在前后端分离的登录中,这个默认行为则 ...
- ajax数据请求2(json格式)
ajax数据请求2(json格式) <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- hibernate+spring mvc,解决hibernate对象懒加载,json序列化失败
在使用spring MVC时,@ResponseBody 注解的方法返回一个有懒加载对象的时候出现了异常,以登录为例: @RequestMapping("login") @Resp ...
- 根据传入url请求,返回json字符串
/** * 根据传入url请求,返回json字符串 * @param url * @return * @throws UnsupportedEncodingException */ public st ...
随机推荐
- SQL 数据库事务 存储过程练习
数据库事务: 数据库事务(Database Transaction) 是指作为单个逻辑工作单元执行的一系列操作. 事务处理可以确保除非事务性单元内的所有操作都成功完成,否则不会永久更新面向数据的资源. ...
- Appuim学习路-Appuim介绍
(学一个东西,总的知道它支持什么.为什么要选择它吧?所以我就去看github上的介绍了.发现大家介绍的来源大多来自于此) Appium是一个开源的自动化框架,是跨平台的,允许所有平台使用同一套AP ...
- OpenCV(图像处理)—访问像素的三种方法
方法一:用指针访问像素 #include <opencv2/opencv.hpp> #include <opencv2/core/core.hpp> #include < ...
- tf.equal()
equal( x, y, name=None ) 对输入的 x 和 y 两个 Tensor 逐元素(element-wise)做 (x == y) 逻辑比较,返回 bool 类型的 Tensor. 参 ...
- Codeforces Beta Round#2
Codeforces Beta Round#2 http://codeforces.com/contest/2 A 模拟题 #include<bits/stdc++.h> using na ...
- Spring配置连接池
---------------------siwuxie095 Spring 配置连接池 1.Spring 配置内置连接 ...
- 源码安装php时出现configure: error: xml2-config not found. Please check your libxml2 installation
1.检查是否安装了libxml 包 > rpm -qa|grep libxml2 2.如果没有则安装 > yum install libxml2 > yum install libx ...
- Spring框架的事务管理的分类
1. Spring的事务管理的分类 1. Spring的编程式事务管理(不推荐使用) * 通过手动编写代码的方式完成事务的管理(不推荐) 2. Spring的声明式事务管理(底层采用AOP的技术) * ...
- 【转】HttpRuntime的认识与加深理解
原文:http://www.cnblogs.com/whtydn/archive/2009/10/16/1584418.html 下面最先介绍HttpRuntime的Web.config里的配置 ...
- Java WebService 知识点汇总
java webservice 获取传入IP axis.jar servlet.jar MessageContext mMsgContext = MessageContext.getCurren ...