springmvc json数据
的
@RequestMapping("/getAllEdu")
@ResponseBody
public void getAllEdu(HttpServletRequest request,HttpServletResponse response){
List<Education> eduList = eduService.findAll();
//request.setAttribute("edus", edus); //response.setCharacterEncoding("UTF-8");
//response.setContentType("text/html");
response.reset();
response.setCharacterEncoding("UTF-8");
//response.setContentType("application/json;charset=utf-8");
response.setContentType("text/html"); JSONArray members = new JSONArray();
PrintWriter out= null;
try {
out= response.getWriter();
for(Education e:eduList){
JSONObject member = new JSONObject();
member.put("eduid", e.getId());
member.put("edutitle", e.getEdutitle());
member.put("objective", e.getObjective());
member.put("contents", e.getContents());
member.put("schedule", e.getSchedule());
member.put("duration", e.getDuration());
member.put("trainerName", e.getTrainerName());
member.put("department", e.getDepartment());
member.put("trainee", e.getTrainee());
member.put("remarks", e.getRemarks());
members.add(member);
}
out.write(members.toString()); } catch (Exception e) {
System.out.println(e.getMessage());
} //out.flush();
out.close();
//return "/eduController/eduManager";
} //第二种方式
@RequestMapping(value="/getAllEdu", )
@ResponseBody
public List<Education> getAllEdu(HttpServletRequest request,HttpServletResponse response){
List<Education> eduList = eduService.findAll();
return eduList;
}
springmvc json数据的更多相关文章
- SpringMVC JSON数据交互
本节内容: @RequestBody @ResponseBody 请求json,响应json实现 前端可以有很多语言来写,但是基本上后台都是java开发的,除了c++(开发周期长),PHP和#Net( ...
- springmvc json 数据
这里是controllor层 @RequestMapping("/traceupdatestatus") @ResponseBody public boolean traceupd ...
- springmvc json数据返回前台,中文乱码
@ResponseBody@RequestMapping(value = "selectProvinces",produces = "text/json;charset= ...
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
最近angularjs post到后台 400一头雾水 没有任何错误. 最后发现好文,感谢作者 SpringMVC中出现" 400 Bad Request "错误(用@Respon ...
- 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- SpringMVC之json数据传递
json是一种常见的传递格式,是一种键值对应的格式.并且数据大小会比较小,方便传递.所以在开发中经常会用到json. 首先看一下json的格式: {key1:value1,key2:value2} 每 ...
- springMVC框架下JQuery传递并解析Json数据
springMVC框架下JQuery传递并解析Json数据
- idea+springmvc+spring+mybatis+maven整合返回json数据webapi
首先看一张目录结构图: : 创建步骤: 1.创建maven webapp工程, 创建完后的目录结构为: 2.添加项目依赖(添加jar包) 需要的jar包: spring-webmvc, spring ...
- (转)springMVC框架下JQuery传递并解析Json数据
springMVC框架下JQuery传递并解析Json数据 json作为一种轻量级的数据交换格式,在前后台数据交换中占据着非常重要的地位.Json的语法非常简单,采用的是键值对表示形式.JSON 可以 ...
随机推荐
- mysql数据库root密码忘记的修改
注:此方法root的密码可以设置成功,但是重新开启服务时可能会出现中断的异常. 1.修改MySQL的root密码,需要先关闭MySQL的服务 2.进入命令行窗口,进入MySQL的安装路径bin目录下, ...
- c/s架构
C/S 结构,即大家熟知的客户机和服务器结构.它是软件系统体系结构,通过它可以充分利用两端硬件环境的优势,将任务合理分配到Client端和Server端来实现,降低了系统的通讯开销.目前大多数应用软件 ...
- Python - 字母算术谜题
如: SEND + MORE == MONEY 9567 + 1085 == 10652 字母和数字一一对应 首字母不为0 解法: import re from itertools import ...
- 《Windows驱动开发技术详解》之读写操作
缓冲区方式读写操作 设置缓冲区读写方式:
- qtp中vb脚本,经典收藏
1.在脚本运行过程中屏蔽鼠标键盘输入 SystemUtil.BlockInput ‘开始处 这里是你的脚本 SystemUtil.UnblockInput ’结尾处 ----------------- ...
- 用Replace Pioneer 提取正则内容
推荐用软件Replace Pioneer完成,支持正则表达式和文本替换,提取,很灵活容易. 以下举例说明怎样把<a href 和 </a>之间的内容提取出来,其他的全部删除. 1. ...
- sql 在将 nvarchar 值 转换成数据类型 int 时失败。
假设有存储过程:proc_test2 create proc proc_test2 @Id int begin as declare @sql varchar(max) @sql = 'select ...
- java IO类图
- hdu_1181_变形课(dfs)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1181 题意:中文题,不解释 题解:直接DFS #include<cstdio> #incl ...
- 剑指offer 二进制1中的个数
算法-求二进制数中1的个数 问题描述 任意给定一个32位无符号整数n,求n的二进制表示中1的个数,比如n = 5(0101)时,返回2,n = 15(1111)时,返回4 这也是一道比较经典的题目了, ...