zoukankan      html  css  js  c++  java
  • thymeleaf中相对路径的两种方式

    先看代码:

    @Controller
    @RequestMapping("/I18n/aaa")
    public class I18nController {
    
        @Autowired
        private LocaleResolver localeResolver;
    
        @RequestMapping("use")
        public String useI18n(HttpServletRequest request, HttpServletResponse response, Model model){
            //model.addAttribute("msg","信息");
            request.getSession().setAttribute("msg","提示信息");
            localeResolver.setLocale(request,response, Locale.CHINA);
            return "I18n";
        }
    }
    <img src="../static/images/1.png" th:src="@{/images/1.png}"/><!--http://localhost:9090/learn-thymeleaf116/images/1.png-->
    <img src="../static/images/1.png" th:src="@{images/1.png}"/><!--http://localhost:9090/learn-thymeleaf116/I18n/aaa/images/1.png-->

    这里主要images前面带/和不带/的区别:

    前面加"/":访问的路径是从服务器的根路径而言的,就是application.yml里面配置的context-path,上我我配置的是/learn-thymeleaf116,所以访问路径为http://localhost:9090/learn-thymeleaf116/images/1.png。

    前面不加"/":访问路径是相对于当前的路径而言的,比如上面的第二个,这个请求的的路径为http://localhost:9090/learn-thymeleaf116/I18n/aaa/use,相对于他的当前路径就是去掉use,所以最终的访问路径就是http://localhost:9090/learn-thymeleaf116/I18n/aaa/images/1.png

  • 相关阅读:
    Wayland中的跨进程过程调用浅析
    设计模式总结
    C语言---整型字符串转换
    抽象工厂模式
    SVNclient安装与使用
    [置顶] MyEclipse下安装插件方法(properties文件编辑器Propedit为例)
    脑筋急转弯的歧义性
    脑筋急转弯的歧义性
    从和式积分到定积分
    从和式积分到定积分
  • 原文地址:https://www.cnblogs.com/wldbk/p/12201233.html
Copyright © 2011-2022 走看看