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>

其次,用到ControllerGetMapping
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">
posted @ 2023-08-05 22:20  thomas_blog  阅读(4)  评论(0编辑  收藏  举报