Spring Boot问题总结
访问无响应
指定包
@ComponentScan(basePackages = "com.example")
浏览器访问跨域问题
将所有请求全部放行
而且每个请求都要加
@CrossOrigin(origins = "*")
get返回html
html放后端,首先dependency
要依赖thymeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
其次,用到Controller
和GetMapping
http://127.0.0.1:8080/home.html
html目录必须是:\src\main\resources\templates
@Controller
public class DemoApplication {
@GetMapping("/home.html")
public String home(Model model) {
System.out.println("home\n");
return "home";
}
}
html中含有图片
图片路径必须是:\src\main\resources\static
<img th:src="@{img/led.png}" class="mx-auto d-block">