springBoot mvc 项目结构 开发 热部署
spring mvc拥有默认配置
热部署
thyleafe如何交换数据
基础的注解使用和需要注意的问题
1常用表单数据接收方式
利用url传递参数,@Pathvariable注解接收参数
@GetMapping(value = "/hello/{id}")
public String hello(@PathVariable("id") Integer id){
return "ID:" + id;
}
2参数名取值
@PostMapping(value = "/post")
public String post(@RequestParam(name = "name") String name,
@RequestParam(name = "age") Integer age) {
String content = String.format("name = %s,age = %d", name, age);
return content;
}
3SpringBoot文件上传
指定上传文件大小
spring.http.multipart.maxFileSize=200MB
spring.http.multipart.maxRequestSize=200MB
spring.servlet.multipart.max-request-size = 200MB
spring.servlet.multipart.max-file-size = 200MB
Html表单
<form action="fileUploadController" method="post" enctype="multipart/form-data">
上传文件:<input type="file" name="filename"/><br/>
<input type="submit"/>
</form>
Controller
@RequestMapping("/fileUploadController")
public String fileUpload(MultipartFile filename) throws Exception{
System.out.println(filename.getOriginalFilename());
filename.transferTo(new File("e:/"+filename.getOriginalFilename()));
return "ok";
}
在使用thymeleaf的注意事项
Html中添加约束
<html xmlns:th="http://www.thymeleaf.org">