一、在resource目錄下面建立文件夾,里面方靜態頁面。
路徑:src\main\resources\static\page\index.html
訪問:http://localhost:8080/page/index.html
注意:后綴一定要html或者htm,否則打不開。
二、Spring Controller返回頁面
訪問:http://localhost:8080/index
注意:前端不能獲取后台傳遞值,因為html不支持EL表達式。jsp或者模板引擎才支持
@Controller public class HelloController { @RequestMapping("/index") public String index(){ System.out.println("coming......"); return "page/index.html"; } @RequestMapping("/index2") public ModelAndView index2(ModelAndView modelAndView){ System.out.println("coming......"); modelAndView.addObject("name","tom"); modelAndView.setViewName("page/index.html"); return modelAndView; } }