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 @   thomas_blog  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2022-08-05 Qt绘图设备QPicture
2022-08-05 Qt绘图设备QImage
点击右上角即可分享
微信分享提示