ModelAndView

如:前台:

//查看公告
		function look() {
			var row = $('#dg').datagrid('getSelected');
			if(row) {
				var id = row.id;
				window.location.href = "xxLook?id=" + id;
			}

		}

如果出现乱码问题需要加编码:

window.location.href = "look?dwlx=" +encodeURI(encodeURI(dwlx))+"&ssnd="+ssnd+"&sspc="+sspc;
		

或者后台接收时:

 title= new String( title.getBytes("iso-8859-1"), "UTF-8");




后台:

// 查看
	@GetMapping("/xxLook")
	public ModelAndView look(String id) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("azcbdxxlook");
		AzcBdxx azcBdxx = service.getById(id);
		mv.addObject("azc", azcBdxx);
		return mv;
	}

返回的视图azcbdxxlook.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




安置处查看




	
士兵基本信息
身份证号码 ${azc.sfzhm } 姓名 ${azc.xm } 籍贯 ${azc.jg }

如果后台返回的为集合,前台可以用jstl遍历,如:

@GetMapping("/xxLook")
		public ModelAndView noticeLook(String id){
			ModelAndView andView=new ModelAndView();
			andView.setViewName("msgfxblook");
		
			MsgFxb msgFxb=service.getMsgFxbById(id);
			andView.addObject("title",msgFxb.getXxbt() );
			
			List list=service.getAppdixList(id);
			List imglist=new ArrayList<>();
			List imgid=new ArrayList<>();
			
			
			for(Appendix a:list){
				
				imglist.add("../assets/img/"+a.getFjmc());
				imgid.add(a.getId());
			}
			andView.addObject("img", imglist);
			andView.addObject("imgid", imgid);
			
			return andView;
		}
		
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>




法宣办查看
 




  
					
					        
					
					   
					      
					     
信息标题 ${title}
附件
>

再如:

//返回商品展示视图
	@GetMapping("/goodslook")
	public ModelAndView goGoods(HttpServletRequest req) throws UnsupportedEncodingException{
		req.setCharacterEncoding("utf-8");
		ModelAndView mv=new ModelAndView();
		String title=req.getParameter("title");
		   title= new String( title.getBytes("iso-8859-1"), "UTF-8");
		System.out.println("分类"+title);
		classfiy.setTitle(title);
		mv.setViewName("goodslook");
		List list=service.getGoods(classfiy);
	//	System.out.println(list);
		mv.addObject("gl", list);
		return mv;
	}
goodslook.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




Insert title here


	
		
	







你可能感兴趣的:(Spring)