Spring控制器响应(action)请求的几种处理方式,如返回JSON,MODEL MODELVIEW,STRING
来源:互联网 发布:知识管理 知乎 编辑:程序博客网 时间:2024/04/29 18:46
Controller:package **.web.controller;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.http.HttpRequest;import org.apache.http.HttpResponse;import org.apache.log4j.Logger;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.servlet.ModelAndView;import com.google.gson.JsonObject;import com.hunantv.ott.loganalysis.persistence.beans.TestBean;/** * this class just for example ,please read spring reference in detail. * * just for controller use case demo by xiaohelong */import dwz.business.info.News;import dwz.business.info.NewsType;import dwz.persistence.BaseConditionVO;import dwz.web.BaseController;@Controllerpublic class OttControlerTest extends BaseController{static Logger log = Logger.getLogger(OttControlerTest.class.getName());@RequestMapping("/Test")@ResponseBodypublic TestBean test (){log.debug("Test function");TestBean testBean=new TestBean();testBean.setName("haha");return testBean;}@RequestMapping("/TestList")@ResponseBodypublic List<TestBean> testList (){log.debug("TestList function");List<TestBean> testBeanList=new ArrayList<TestBean>();TestBean testBean1=new TestBean();testBean1.setName("haha");TestBean testBean2=new TestBean();testBean2.setName("hehe");testBeanList.add(testBean1);testBeanList.add(testBean2);return testBeanList;}@RequestMapping("/TestJSONObject")public void testReturrnJSONWithoutBean(HttpServletRequest request,HttpServletResponse response) throws IOException{log.debug("TestJSONObject function");response.setContentType("application/json"); response.setCharacterEncoding("UTF-8");PrintWriter writer=response.getWriter();JsonObject jsonObject=new JsonObject();jsonObject.addProperty("name","hehe jsonobject");writer.println(jsonObject.toString());writer.close();}@RequestMapping("/TestReturnPage")@ResponseBodypublic String testReturrnPage(){log.debug("TestReturnPage");return "/testpage";}/** * The difference between model and modelandview is just sematic * */ @RequestMapping("/TestReturnModel")public String testReturnModel(Model model){log.debug("testReturrnModel");model.addAttribute("testmodel", "hello model");return "testpage";}/** * The difference between model and modelandview is just sematic * */ @RequestMapping("/TestReturnModelAndView")public ModelAndView testReturnModelAndView(){log.debug("testReturrnModel");ModelAndView mav = new ModelAndView("testpage");mav.addObject("testmodel", "hello test model");return mav;}/*@RequestMapping("")public String list(BaseConditionVO vo, Model model) {List<News> newsList = newsMgr.searchNews(vo);int totalCount = newsMgr.searchNewsNum(vo);vo.setTotalCount(totalCount);model.addAttribute("newsTypes", NewsType.values());model.addAttribute("newsList", newsList);model.addAttribute("vo", vo);return "/management/news/list";}*/}Class TestBean:package **.persistence.beans;public class TestBean {public String getName() {return name;}public void setName(String name) {this.name = name;}String name;}
0 0
- Spring控制器响应(action)请求的几种处理方式,如返回JSON,MODEL MODELVIEW,STRING
- spring mvc 处理方法的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void
- Spring MVC返回json数据的几种方式
- 四 :spring mvc处理方法支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void 使用方法
- Struts2返回json的几种方式
- spring返回json的四种方式
- JSON处理的几种方式
- Ajax请求到action,action返回整个页面的方式
- Ajax请求到action,action返回整个页面的方式
- SpringMVC的几种返回方式(get请求)
- spring mvc 响应界面跳转的几种方式
- json返回到客户端的几种方式
- ajax请求后台返回json的两种处理方法
- string解析为json的几种方式
- struts2返回json和几种方式
- @RequiresPermissions 控制权限的异常处理以及Ajax方式请求时返回json
- Android Volley框架的几种post提交请求方式(xml->xml json->json xml->json)
- 2016-12-03(两种处理JSON返回页面的方式、分页,ModelAndView和Model的区别,<C:forEach>注意)
- HDU 5037 Frog(北京网络赛F题)
- love2d 学习笔记1
- 文件的读写
- PHP加减乘除运算
- session相关
- Spring控制器响应(action)请求的几种处理方式,如返回JSON,MODEL MODELVIEW,STRING
- hdu 5035 Delivery 概率题 2014 ACM/ICPC Asia Regional Beijing Online
- hdu 5023——A Corrupt Mayor's Performance Art
- hive导入数据到hbase
- qt实现的窗口吸附屏幕边缘,动画隐藏显示的效果,类似于qq主窗口 吸附 隐藏的效果
- HDU 5038 Grade(北京网络赛G题)
- jQuery中倒计时效果
- poj1208 The Blocks Problem,模拟,vector
- HDU 3191 How Many Paths Are There