SpringBoot不使用模板引擎直接返回html


一、在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;
    }
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM