@RequestMapping(value="/welcome",method={RequestMethod.GET}) public ModelAndView getFirstPage(HttpServletRequest request) { //welcom就是视图的名称(welcom.ftl) ModelAndView mv = new ModelAndView("welcom"); mv.addObject("name", "My First Spring Mvc"); return mv; } }
在url上敲http://localhost:8080/welcome就会到WEB-INF/view/welcom.ftl页面渲染数据 welcom.ftl页面 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> Hello ${name} </body> </html>