
本文共 4056 字,大约阅读时间需要 13 分钟。
Spring Boot������������
���������������������controller
������@SpringBootApplication
������������������������������������������������
@SpringBootApplication(scanBasePackages = "zyc")
������������������������@SpringBootApplication
���������@SpringBootConfiguration
���@EnableAutoConfiguration
���@ComponentScan
���������������
������@ConfigurationProperties ������������
������
���������������User
���������������������������������
������������
application.properties
���������������������User
������������@ConfigurationProperties
���������������������������"myuser"
@Component@ConfigurationProperties(prefix = "myuser")public class UserConfig { // ���������������������������}
������@SpringBootApplication ���������
@SpringBootApplication
������������������������������������������
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
������������������������
������devTools
������������������������������������������������������������������������������������������
org.springframework.boot spring-boot-devtools true
������YAML ������������
YAML ���������������
:
:
, -
���������������������������key: value
key: { key1: value1 key2: value2}
key: [value1, value2, value3]
YAML ���������������������
������������������������
������������������������������
spring: mvc: static-path-pattern: "/static/**"
������������������������
������������������������������������������������������������
HandlerInterceptor
������������������������������
public class myInterceptor implements HandlerInterceptor { @Override public boolean preHandle() { return true; } @Override public boolean postHandle() { return true; } @Override public boolean afterCompletion() { return true; }}
������������������
import org.springframework.boot.web.servlet.interceptor.WebMvcConfigurer;import myInterceptor;@Configurationpublic class WebConfig implements WebMvcConfigurer { @Override void addInterceptors LennonIntercepror interceptor) { super.addInterceptors(interceptor); }}
���������������������������������������������������������������������������������������������������������
spring: mvc: static-path-pattern: "/resources/**"
������������������������
@RequestParam
������@Uploaded
���������������������������������������
spring: servlet: multipart: max-file-size: 10MB max-request-size: 100MB
���������������������������
@PostMapping("/upload")public JsonResult upload(@RequestParam("image") MultipartFile multipartFile) { if (!multipartFile.isEmpty()) { String originalFilename = multipartFile.getOriginalFilename(); String substring = originalFilename.substring(originalFilename.lastIndexOf(".")); // ��������������������� String uuid = UUID.randomUUID().toString().replaceAll("-", ""); String newName = uuid + substring; try { multipartFile.transferTo(new File(path + newName)); return new JsonResult(true, "������������������"); } catch (IOException e) { return new JsonResult(false, "������������������"); } } return new JsonResult(false, "������������������");}
������������������
404 ������������
404.html
������src/main/resources/templates/
���������5XX ������������
5xx.html
������5xx.html
������src/main/resources/templates/
���������������������
���application.yaml
������������������������
spring: profiles: active: dev # ������������������env: - Denis=dev - Denis=prod
������������������������DENIS
������������������������������������������������application.properties
������������������������������application-${spring.profile}.properties
������
发表评论
最新留言
关于作者
