Spring 开发笔记
2015-07-17 09:25
567 查看
1、使用@ResponseBody返回结果,不加则返回URL,转向指定的URL。例如:
上述代码中,不加@ResponseBody则转向:【原URL】/products/list地址的访问,添加后,则返回字符串"products/list"到前端页面。
@RequestMapping(value = "/list", method = RequestMethod.GET) public @ResponseBody String getProducts(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("TEST IS OK!"); request.setAttribute("name", "helloWord"); // response.setContentType("text/html;charset=utf-8"); // response.setCharacterEncoding("UTF-8"); // PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8")); // out.println("<h1>TEST IS OK!</h1>"); // out.close(); return "products/list"; }
上述代码中,不加@ResponseBody则转向:【原URL】/products/list地址的访问,添加后,则返回字符串"products/list"到前端页面。
相关文章推荐
- Java NIO原理图文分析及代码实现
- android studio 项目 转换成eclipse
- java计算时间差的方法
- java基金会成立Set
- struts2 Properties
- spring
- java中如何导入03和07版的Excel文件数据,存入到数据库
- Java的内存分析
- java--实现将文字生成二维码图片,并在中间附上logo,下方附上文字
- Java回调函数机制
- 32位64位Eclipse和jdk对应关系
- 解决eclipse启动插件时PermGen space问题
- java.util.concurrent
- java 枚举常见用法
- Eclipse开发Android,Java项目快捷键技巧
- 解决eclipse svn 返回历史版本(update to version)异常
- java接口与抽象类的区别之缺省适配模式 .
- eclipse maven plugin 插件 安装 和 配置
- 在 Java EE 组件中使用 Camel Routes
- 除非万不得已,别 Catch!