Spring 开发笔记

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"到前端页面。

posted @ 2015-07-17 09:25  hongweigg  阅读(5)  评论(0)    收藏  举报