您的位置:首页 > 编程语言 > Java开发

Spring 开发笔记

2015-07-17 09:25 567 查看
1、使用@ResponseBody返回结果,不加则返回URL,转向指定的URL。例如:

@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"到前端页面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: