配置文件
server.port=81
server.servlet.context-path=/augur
server.servlet.session.timeout=100
server.tomcat.uri-encoding=UTF-8
#视图解析器配置:禁用 thymeleaf 缓存
spring.thymeleaf.cache=false
#windows 文件上传路径(springboot可自定义参数,后端用@value注解接受)
fileUploadPath = E:/files/
#linux 文件上传路径
#fileUploadPath = /home/files/
# springboot2.0之后更新了配置 单个文件上传大小限制
spring.servlet.multipart.maxFileSize = 2000MB
#springboot2.0之后更新了配置 单次请求文件大小限制
spring.servlet.multipart.max-request-size = 2000MB
maven依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--springboot无法直接访问templates下的页面,需要导入thymeleaf才可以访问-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- @Slf4j 日志注解使用的依赖-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>
关于thymeleaf的介绍:
springboot推荐的模板引擎,主要用于编写动态页面,比jsp执行效率高。springboot只需要导入1个依赖即可整合thymeleaf,使用方便快捷,在springboot项目的resources/templates目录下创建index.html页面,写controller,使其跳转到index.html即可。
springboot 的web项目中,static目录一般放静态资源,而templates目录一般放动态页面。static目录下的资源可以通过ip:端口/上下文路径/../静态资源文件名 直接访问。默认没有权限管理。
// 访问templates下的页面
// 方法1,字符串;如果要带数据,方法参数可以加个ModelAndView
@GetMapping("info1")
public String show(){
return "info";
}
// 方法2,返回ModelAndView
@GetMapping("/")
public ModelAndView fileUpload(){