xml配置文件如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<velocity.version>1.7</velocity.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
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页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
</head>
<body>
<h1>Login页面</h1>
</body>
</html>
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