1.freemarker+thymeleaf
直接添加依赖就行
2.freemarker+jsp
直接添加依赖就行
3.thymeleaf+jsp
添加依赖
org.springframework.boot spring-boot-starter-thymeleaforg.springframework.boot spring-boot-starter-weborg.apache.tomcat.embed tomcat-embed-jasperprovided javax.servlet jstl
WebMvcConfig.java
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/jsp/",".jsp").viewClass(HandleInternalResourceVivwExists.class);
registry.order(1);
}
}
HandleInternalResourceVivwExists
public class HandleInternalResourceVivwExists extends InternalResourceView {
@Override
public boolean checkResource(Locale locale) throws Exception {
File file = new File(getServletContext().getRealPath("/")+getUrl());
return file.exists();
}
}
helloController
package com.example.thyjsp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class helloController {
@RequestMapping("/01")
public String hello2(){
return "01";
}
@RequestMapping("/02")
public String hello3(){
return "02";
}
}
4.freemarker+thymeleaf+jsp
同三
01.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
${"jsp"}
02.html
Title
03.ftlh
Title
${"ftlh"}



