Java
栈的简单应用-浏览器页面导航
栈的链表实现
栈的数组实现
使用单链表实现LRU缓存
使用 单链表简单实现一个LRU缓存。
单链表的简单实现
使用Java实现一个单链表,有如下功能:
- 插入元素
- 根据索引获取元素
- 判断链表中是否存在元素
- 获取元素索引
- 删除元素
- 反转链表
- 判断回文字符串
实现一个自定义数组
Spring声明式事务的使用
1 从@Transactional
注解开始
#
@Transactional
注解是使用spring-transaction的最便捷方式。也是使用Spring框架开发最先接触的内容。
当你在一个服务的方法上使用@Transactional
注解时,意味着你希望为此方法开启事务支持。如果你的项目成功配置了数据源和事务管理器,Spring会为此方法使用如下默认设置开启事务:
在SpringBoot中使用MessageSource
几个说明:
properties配置文件中,;spring.messages.basename
必须要加classpath前缀。如spring.messages.basename=classpath:i18n/messages
必须要手动配置;MessageSource
,springboot不会自动配置之- 如果使用
MessageSource.getMessage()
方法,第一个参数的引用形式为"code"
,而不是"{code}"
或者"${code}"
。如messageSource.getMessage("test.msg", null,Locale.getDefault());- 在配置
LocalValidatorFactoryBean
之后,才可以在javax.validation.constraints
包下的注解(@Size
,@NotNull
...)下的message属性中使用"{code}"
的形式声明校验提示信息。如@NotNull(message = "{leftTime.not.null}")
;- springMVC的locale配置和JVM的locale配置不一样,在application.properties中配置的
spring.mvc.locale=zh_CN
实际上配置的是WebMvcProperties
,在获取消息时,locale信息应该使用webMvcProperties.getLocale()
1获取而不是使用Locale.getDefault()
获取。
MessageSource is a powerful feature available in Spring applications. This helps application developers handle various complex scenarios with writing much extra code, such as environment-specific configuration, internationalization or configurable values.
One more scenario could be modifying the default validation messages to more user-friendly/custom messages.
In this tutorial, we'll see how to configure and manage custom validation MessageSource in the application using Spring Boot.
...使用Logback记录日志
Logback是Java应用中使用最广的日志框架之一,它是 其前辈框架Log4j的替代者。相比Log4j,Logback在日志处理速度、配置多样性、对旧日志文件的处理灵活性上均要优于Log4j。
这篇文章将介绍Logback的主要组成结构并指导你使用Logback构建更好的程序。
...