maven中加入thymeleaf依赖
<!--支持html页面-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
写一个controller
注解为@Controller(返回页面),@RestController为返回json
@Controller
public class TestUploadFile {
@RequestMapping(value = "testupload", method = RequestMethod.GET)
public String testUpload() {
return "testload";
}
}
将页面放在resources目录下的templates文件夹
<!DOCTYPE html>
<html lang="zn">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
</head>
<body>
springmvc上传文件
<form name="form1" action="/wx/auth/upload" method="post" enctype="multipart/form-data">
<input type="file" name="upload_file" />
<input type="submit" value="springboot上传文件" />
</form>
</body>
</html>
校验
访问:http://localhost:8080/testupload 页面正常显示