欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

这是唯一一个

程序员文章站 2022-07-10 19:07:02
业务场景spring boot + mybatis后台管理系统框架;layUI前端界面;shiro权限控制,ehCache缓存;开发背景maven :3.3.3JDK : 1.8Intellij IDEA : 2017.2.5 开发工具spring boot :1.5.9.RELEASEmybatis 3.4.5 :dao层框架pageHelper : 5.1.2httpClient : 4.5.3layui 2.2.3 :前端框架shiro 1.4.......
  • 业务场景

  • spring boot + mybatis后台管理系统框架;
  • layUI前端界面;
  • shiro权限控制,ehCache缓存;

开发背景

maven :3.3.3 
JDK : 1.8 
Intellij IDEA : 2017.2.5 开发工具 
spring boot :1.5.9.RELEASE 
mybatis 3.4.5 :dao层框架 
pageHelper : 5.1.2 
httpClient : 4.5.3
layui 2.2.3 :前端框架 
shiro 1.4.0 :权限控制框架 
druid 1.1.5 :druid连接池,监控数据库性能,记录SQL执行日志 
thymeleaf :2.1.4.RELEASE,thymeleaf前端html页面模版 
log4j2 2.7 :日志框架 
EHCache : 2.5.0 
ztree : 3.5.31

项目框架

spring boot + mybatis + shiro + layui + ehcache 
项目源码:(包含数据库源码) 
 

spring boot之静态资源路径配置

静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取。

在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,从这里可以看出这里的静态资源路径都是在classpath中(也就是在项目路径下指定的这几个文件夹)

试想这样一种情况:一个网站有文件上传文件的功能,如果被上传的文件放在上述的那些文件夹中会有怎样的后果?

网站数据与程序代码不能有效分离;
当项目被打包成一个.jar文件部署时,再将上传的文件放到这个.jar文件中是有多么低的效率;
网站数据的备份将会很痛苦。

此时可能最佳的解决办法是将静态资源路径设置到磁盘的某个目录。与应用程序分离。

在Springboot中可以直接在配置文件中覆盖默认的静态资源路径的配置信息:

application.properties配置文件如下:
# 静态资源路径配置
wyait.picpath=D:/demo-images/

spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${wyait.picpath}

注意wyait.picpath这个属于自定义的属性,指定了一个路径,注意要以/结尾;

spring.mvc.static-path-pattern=/ 表示所有的访问都经过静态资源路径;

spring.resources.static-locations 在这里配置静态资源路径,前面说了这里的配置是覆盖默认配置,所以需要将默认的也加上否则static、public等这些路径将不能被当作静态资源路径,在这个最末尾的 file:${wyait.picpath} ==file:${wyait.picpath}==, 
加 file :是因为指定的是一个具体的硬盘路径,其他的使用classpath指的是系统环境变量。

问题

图片或静态资源直接放在wyait.picpath=D:/demo-images/目录下,

[2018-04-08 22:05:32.095][http-nio-8077-exec-3][ERROR][org.apache.juli.logging.DirectJDKLog][181]:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "0", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "0", template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) ~[thymeleaf-2.1.6.RELEASE.jar:2.1.6.RELEASE]

原因应该是在项目集成shiro时,shiro对contextPath/后面的第一层path访问时,对标点“.”进行了截取,实际请求变成了: 交给dispatcherServlet处理,没有找到匹配的view视图“0”,就报错。

本文地址:https://blog.csdn.net/baidu_30507937/article/details/107678335