response.getWriter().println和@ResponseBody的比较及同时使用(用于回调函数)
@RequestMapping(value = "/test", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public Object test(@RequestParam Map<String, Object> params, HttpServletRequest request,
HttpServletResponse response) {
logger.info("mobileMethodEntrance请求成功");
// 方法参数
String methodString = request.getParameter("method");
// 跨域
String callbackfun = request.getParameter("callback");
try {
// 反射
Class<DianliMobileApiController> clazz = (Class<DianliMobileApiController>) Class
.forName("com.jysoft.resource.control.DianliMobileApiController");
// 实例化
DianliMobileApiController ins = clazz.newInstance();
// 注入属性
ins.service = SpringUtils.getBean(DianLiMobileApiService.class);
ins.vService = SpringUtils.getBean(VideoService.class);
ins.sservice = SpringUtils.getBean(SupervisionService.class);
// 获取方法
Method method = clazz.getMethod(methodString, HttpServletRequest.class, HttpServletResponse.class);
// 方法调用
Object result = method.invoke(ins, request, response);
Object res = JSON.toJSON(result);
if (!StringUtil.isEmptyString(callbackfun)) {
callbackfun += "(" + res + ")";
response.getWriter().println(callbackfun);
return null;
}
return res;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
备注:
@RequestMapping("/login")
@ResponseBody
public User login(User user){
return user;
}
User字段:userName pwd
那么在前台接收到的数据为:'{"userName":"xxx","pwd":"xxx"}'
效果等同于如下代码:
@RequestMapping("/login")
public void login(User user, HttpServletResponse response){
response.getWriter.write(JSONObject.fromObject(user).toString());
}
response.getWriter().println和@ResponseBody的比较及同时使用(用于回调函数)的更多相关文章
- @ResponseBody 与 response.getWriter.write
@responseBody注解的使用 1. @responseBody注解的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通 ...
- out.print()和response.getWriter().write()区别
1.print()和write()区别: write():表示的是仅支持输入字符类型数据,字符,字符数组和字符串等, print():表示的是将各种数据类型(包括object)的数据通过默认编码换成b ...
- [转]response.getWriter().write()与out.print()的区别
原文地址:http://blog.csdn.net/javaloveiphone/article/details/8133772 1.首先介绍write()和print()方法的区别: (1).w ...
- response.getWriter().write()与out.print()的区别
1.首先介绍write()和print()方法的区别: (1).write():仅支持输出字符类型数据,字符.字符数组.字符串等 (2).print():可以将各种类型(包括Object)的数据通 ...
- response.getWriter().write()与out.print()的区别 (转)
来自:http://www.cnblogs.com/zhwl/p/3623688.html 1.首先介绍write()和print()方法的区别: (1).write():仅支持输出字符类型数据,字 ...
- response.getWriter().write()与out.print()的区别(转)
1.首先介绍write()和print()方法的区别: (1).write():仅支持输出字符类型数据,字符.字符数组.字符串等 (2).print():可以将各种类型(包括Object)的数据通 ...
- response.getWriter().write()与out.print()的区别(转)
1.首先介绍write()和print()方法的区别: (1).write():仅支持输出字符类型数据,字符.字符数组.字符串等 (2).print():可以将各种类型(包括Object)的数据通过默 ...
- response.getWriter().write()乱码问题
前台代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> & ...
- response.getWriter().wirte和out.print()的区别
1.首先介绍write()和print()方法的区别: (1).write():仅支持输出字符类型数据,字符.字符数组.字符串等 (2).print():可以将各种类型(包括Object)的数据通 ...
随机推荐
- 交叉编译openssl1.1.1a
交叉编译openssl1.1.1a的时候遇到的问题,记录一下,方便下次查找 一.下载源码 1.打开openssl官网,下载openssl-1.1.1.tar.gz源码包. 2.执行下面的命令解压源 ...
- shell脚本4种执行方式
Linux中shell脚本的执行通常有4种方式,分别为工作目录执行,绝对路径执行,sh执行,shell环境执行. 首先,看下我们的脚本内容 [tan@tan scripts]$ ll total -r ...
- c# DirectoryInfo类
- TP5框架模块绑定二级域名
application\config.php 修改 url_domain_deploy 为 true 'url_domain_deploy' => true application\route. ...
- GooglePlay测试支付遇到的问题
推荐谷歌安装器,可以方便地安装谷歌框架及服务 问题列表 1.测试支付时出现:需要验证身份.您需要登录自己google账号 解决:我是使用VPN,VPN地区是日本,但我在google后台设置的发布(下载 ...
- 软件测试_Loadrunner_性能测试_服务器资源监控
使用Loadrunner进行Windows服务器性能监控 将装有Loadrunner的机器叫做监控端,被监控资源的服务器叫做被监控端 一.前置环境设置 1. 设置被监控端管理员账户可用:我的电脑右键- ...
- 使用docker 安装 LNMP
centos7 下 使用docker 安装 LNMP 一.安装 mysql 1 获取 mysql 镜像 docker pull mysql:5.7 2 创建mysql的镜像,并运行 docker ru ...
- csr_matrix
from scipy.sparse import * row = [0,0,0,1,1,1,2,2,2]#行指标col = [0,1,2,0,1,2,0,1,2]#列指标data = [1,0,1,0 ...
- 【Python】编程小白的第一本python(最基本的魔法函数)
Python官网中各个函数介绍的链接:https://docs.python.org/3/library/functions.html 几个常见的词: def (即 define,定义)的含义是创建函 ...
- Coins in a Line I
Description There are n coins with different value in a line. Two players take turns to take one or ...