hibernate-validator如何使用校验框架
作者
目录
* Comma-separated list of basenames, each following the ResourceBundle convention. * Essentially a fully-qualified classpath location. If it doesn't contain a package * qualifier (such as "org.mypackage"), it will be resolved from the classpath root. */ private String basename = "messages"; /** * Message bundles encoding. */ private Charset encoding = Charset.forName("UTF-8"); /** * Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles * are cached forever. */ private int cacheSeconds = -1; /** * Set whether to fall back to the system Locale if no files for a specific Locale * have been found. if this is turned off, the only fallback will be the default file * (e.g. "messages.properties" for basename "messages"). */ private boolean fallbackToSystemLocale = true; /** * Set whether to always apply the MessageFormat rules, parsing even messages without * arguments. */ private boolean alwaysUseMessageFormat = false; @Bean public MessageSource messageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); if (StringUtils.hasText(this.basename)) { messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray( StringUtils.trimAllWhitespace(this.basename))); } if (this.encoding != null) { messageSource.setDefaultEncoding(this.encoding.name()); } messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale); messageSource.setCacheSeconds(this.cacheSeconds); messageSource.setAlwaysUseMessageFormat(this.alwaysUseMessageFormat); return messageSource; } public String getBasename() { return this.basename; } public void setBasename(String basename) { this.basename = basename; } public Charset getEncoding() { return this.encoding; } public void setEncoding(Charset encoding) { this.encoding = encoding; } public int getCacheSeconds() { return this.cacheSeconds; } public void setCacheSeconds(int cacheSeconds) { this.cacheSeconds = cacheSeconds; } public boolean isFallbackToSystemLocale() { return this.fallbackToSystemLocale; } public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) { this.fallbackToSystemLocale = fallbackToSystemLocale; } public boolean isAlwaysUseMessageFormat() { return this.alwaysUseMessageFormat; } public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) { this.alwaysUseMessageFormat = alwaysUseMessageFormat; } protected static class ResourceBundleCondition extends SpringBootCondition { private static ConcurrentReferenceHashMap<String, ConditionOutcome> cache = new ConcurrentReferenceHashMap<String, ConditionOutcome>(); @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String basename = context.getEnvironment() .getProperty("spring.messages.basename", "messages"); ConditionOutcome outcome = cache.get(basename); if (outcome == null) { outcome = getMatchOutcomeForBasename(context, basename); cache.put(basename, outcome); } return outcome; } private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context, String basename) { ConditionMessage.Builder message = ConditionMessage .forCondition("ResourceBundle"); for (String name : StringUtils.commaDelimitedListToStringArray( StringUtils.trimAllWhitespace(basename))) { for (Resource resource : getResources(context.getClassLoader(), name)) { if (resource.exists()) { return ConditionOutcome .match(message.found("bundle").items(resource)); } } } return ConditionOutcome.noMatch( message.didNotFind("bundle with basename " + basename).atAll()); } private Resource[] getResources(ClassLoader classLoader, String name) { try { return new PathMatchingResourcePatternResolver(classLoader) .getResources("classpath*:" + name + ".properties"); } catch (Exception ex) { return NO_RESOURCES; } } } }从上面的MessageSource自动配置可以看出,可以通过spring.message.basename指定要配置国际化文件位置,默认值是“message”。spring boot默认就支持国际化的,默认会去resouces目录下寻找message.properties文件。
这里就不进行过多关于国际化相关信息的介绍了,肯定少不了区域解析www.cppcns.com器。springboot国际化相关知识请参考:Spring Boot国际化(i18n)
到此这篇关于hibernate-validator如何使用校验框架的文章就介绍到这了,更多相关hibernate-validator校验内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
目录
推荐阅读
-
Java实战之医院管理系统的实现
-
elasticsearch索引index之Translog数据功能分析
-
java实现简单发送邮件功能
-
Java实现图片比率缩放
-
Java中的JetCache 实战
-
elasticsearch索引index之engine读写控制结构实现
-
elasticsearch索引index之Mapping实现关系结构示例
-
LeetCode 动态规划之矩阵区域和详情
-
elasticsearch索引的创建过程index create逻辑分析
目录索引的创建过程materOperation方法实现clusterservice处理建立索引修改配置总结索引的创建过程从本篇...
-
java实现上传图片尺寸修改和质量压缩
本文实例为大家分享了java实现上传图片尺寸修改和质量压缩的具体代码,供大家参考,具体内容如下packagecom.zity....
0 条评论
本站已关闭游客评论,请登录或者注册后再评论吧~