Spring Boot 踩坑系列

thymeleaf 静态资源页面无法访问

默认情况下,thymeleaf 的模板路径应该就在
src/main/resources/templates下面,因此我把编写的模板文件放置在此处。

    @RequestMapping("/upload")
    public ModelAndView uploadPage() {
        return new ModelAndView("uploadFile");
    }

结果访问失败.
在我修改了application.yml中thymeleaf 的默认路径后

spring:
  thymeleaf:
    prefix: classpath:/templates/

访问正常

成功显示页面

Could not autowire. No beans of … type found

Springboot+mybatis(注解),在Service层引用Dao层的时候,@Autowired提示异常,但是代码可以运行。

Spring Boot 踩坑系列_第1张图片
Paste_Image.png

推荐解决方法,在MyBatis的映射文件中,加入@Repository注解


Spring Boot 踩坑系列_第2张图片
Paste_Image.png

配置错误界面(Whitelabel Error Page)

Spring Boot中Web应用的统一异常处理
当用户请求一个不存在的页面时,如果系统未配置任何信息,那么系统会显示一个空白的错误页面

Spring Boot 踩坑系列_第3张图片
典型的错误页面

application.properties

server.context-path: 设置访问网站的前缀.

使用@PathVariable配置路径,导致页面的静态资源无法访问的问题

Spring Boot + Thymeleaf using @PathVariable results in 404 of JS





你可能感兴趣的:(Spring Boot 踩坑系列)