解决Thymeleaf页面国际化时显示??login.tip

tech2022-07-10  161

error总结

1. 目录结构(确定是在resources目录结构下)

2. application.properties(指定自定义的目录)

#指定管理国际化资源文件 spring.messages.basename=i20n.login

3.源码(分析)

/** 国际化资源文件如果不是直接在resources目录下 就去application.properties的指定目录去找 再然后就是说 如果你指定的的目录形式不是以‘/’组成 是以'.'组成'.'就将.替换成'/' 然后去对文件进行解析 */ private Resource[] getResources(ClassLoader classLoader, String name) { String target = name.replace('.', '/'); try { return (new PathMatchingResourcePatternResolver(classLoader)).getResources("classpath*:" + target + ".properties"); } catch (Exception var5) { return MessageSourceAutoConfiguration.NO_RESOURCES; } }

而不是!!!

4.版本(可能版本之间也有一些兼容问题吧,下面是小编的版本)

<properties> <!--版本冲突,换一个3.0+的版本--> <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version> <!-- 布局功能的支持程序 thymeleaf3主程序 layout2以上版本 --> <!-- thymeleaf2 layout1--> <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version> </properties> <dependencies> <dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>org.webjars</groupId> <artifactId>bootstrap</artifactId> <version>4.0.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies>

最后一点小问题吧...写国际资源文件的时候,变量记得小写...否则在html页面调用的时候可能会出现拿不到参数的情况

转载于:https://blog.csdn.net/weixin_44006311/article/details/105223847

最新回复(0)