首页 > 代码库 > 数据返回(数据共享,即从后端返回到前端调用,四种(requesst、ModelAndView、Model、Map))

数据返回(数据共享,即从后端返回到前端调用,四种(requesst、ModelAndView、Model、Map))

@Controller
@RequestMapping("/view")//请求父路径
public class GoodsController {

		@RequestMapping("/goodsReturnReq.do")//请求子路径
		public String goodsReturnReq(Goods goods,HttpServletRequest request){
			System.out.println("goodsReturnReq:"+goods);
			request.setAttribute("gds",goods);
			//MySpringMVC02/view/goodsAddOk.jsp  注意:404错误一般都是路径写错了,须仔细检查哪里拼写错了
			//MySpringMVC02/view/goodsAddOK.jsp  这里K一个大写一个小写
			return "goodsAddOK";//请求成功的返回路径
		}
		
		@RequestMapping("/goodsReturnMav.do")
		public ModelAndView goodsReturnMav(Goods goods){
			System.out.println("goodsReturnMav:"+goods);
			ModelAndView mav = new ModelAndView("goodsAddOK");//请求成功的返回路径
			mav.addObject("gds",goods);
			return mav;//返回模型视图
		}
		
		@RequestMapping("goodsReturnModel.do")
		public String goodsReturnModel(Goods goods,Model model){
			System.out.println("goodsReturnModel:"+goods);
			model.addAttribute("gds",goods);//此处是add不是set
			return "goodsAddOK";
		}
		
		@RequestMapping("goodsReturnMap")
		public String goodsReturnMap(Goods goods,Map map){
			System.out.println("goodsReturnMap:"+goods);
			map.put("gds", goods);//Map
			return "goodsAddOK";
		}
}

  

数据返回(数据共享,即从后端返回到前端调用,四种(requesst、ModelAndView、Model、Map))