xml配置文件如下:
org.springframework.boot
spring-boot-starter-parent
1.5.6.RELEASE
UTF-8
UTF-8
1.8
1.7
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-freemarker
2、项目截图
3、详解application.properties文件的配置:
#服务启动端口号
server.port=8080
#访问根路径,默认情况下IntelliJ IDEA是没有访问根路径的,如localhost:8080/请求路径
server.contextPath=/html
###FREEMARKER (FreeMarkerAutoConfiguration)
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
#spring.freemarker.prefix=
spring.freemarker.request-context-attribute=rc
#spring.freemarker.settings.*=
#模板加载后缀
spring.freemarker.suffix=.html
#模板加载路径
spring.freemarker.template-loader-path=classpath:/views/#非templates目录是需要指定模板路径的,thymeleaf默认的前缀是templat
默认情况下,Spring Boot将从类路径或根目录中的/static(/public或/resources或/META-INF/resources)目录中提供静态内容ServletContext。它使用ResourceHttpRequestHandler从Spring
MVC,所以你可以通过添加自己WebMvcConfigurerAdapter和覆盖该addResourceHandlers方法来修改这种行为。
4、login.html页面
TitleLogin页面
5、controller
@Controller
public class HtmlController {
Logger logger = LoggerFactory.getLogger(HtmlController.class);
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login() {
logger.info("=====");
return "/login";
}
}
6、application
@SpringBootApplication
public class HtmlApplication {
public static void main(String[] args) {
SpringApplication.run(HtmlApplication.class, args);
}
}
启动访问,http://localhost:8080/html/login