springboot项目下载
https://spring.io/projects/spring-boot
最下面点击它
或者直接进入这个 https://start.spring.io/
springboot 启动器讲解
springboot 的主程序
主程序中的注解
run方法
springboot 图解
https://www.processon.com/view/link/59812124e4b0de2518b32b6e
springboot 配置文件
yaml
静态资源处理
查看源码的类
模板引擎
在pom中添加依赖
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
这儿要注意用thymeleaf 要引入这个约束
xmlns:th="http://www.thymeleaf.org"
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>hello</h1>
<div th:text="${msg}"></div>
</body>
</html>
在controller中定义
package com.yu.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class controllerHello {
@RequestMapping("/hello")
public String hello(Model model){
model.addAttribute("msg","hello springboot");
return "test";
}
}
springMVC扩展
需要编写一个java类
项目结构
package com.yu.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/a").setViewName("test");
}
}
测试结果