1、springboot统一处理异常注解ExceptionHandler
2、ErrorPage全局异常处理
3、在SpringFramework 5.0 引入了@Indexed注解
4、springBoot配置国际化
5、CRON表达式详解
1.cron表达式:
- cron表达式是由若干数字、空格、符号按一定的规则,组成一组字符串,从而表达时间的信息。与正则表达式类似,都是一个字符串表示一些信息。
2.cron表达式标准结构:
- Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义。
- corn从左到右(用空格隔开):秒 分 小时 月份中的日期 月份 星期中的日期 年份
3.Cron有如下两种语法格式:
- Seconds Minutes Hours DayofMonth Month DayofWeek Year
- Seconds Minutes Hours DayofMonth Month DayofWeek
4.每个字段的含义:
5.特殊字符:
“?”字符:表示不确定的值
“,”字符:指定数个值
“-”字符:指定一个值的范围
“/”字符:指定一个值的增加幅度。n/m表示从n开始,每次增加m
“L”字符:用在日表示一个月中的最后一天,用在周表示该月最后一个星期X
“W”字符:指定离给定日期最近的工作日(周一到周五)
“#”字符:表示该月第几个周X。6#3表示该月第3个周五
更多特殊字符不作赘述!也可以使用cron生成工具生成表达式,再次提醒生成时注意语法格式。两种cron格式很容易混淆。
6、@Order 注解
@Order 注解
@Order注解主要用来控制配置类的加载顺序 :数字越小,越先加载
示例代码:
package com.runlion.tms.admin.constant;
public class AService {
}
package com.runlion.tms.admin.constant;
public class BService {}
package com.runlion.tms.admin.constant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
@Configuration
@Order(2)
public class AConfig {
@Bean
public AService AService() {
System.out.println("AService 加载了");
return new AService();
}
}
package com.runlion.tms.admin.constant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
@Configuration
@Order(1)
public class BConfig {
@Bean
public BService bService() {
System.out.println("BService 加载了");
return new BService();
}
}
测试类:
package com.runlion.tms.admin.constant;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class OrderMain {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext("com.runlion.tms.admin.constant");
}
}
输出结果:
BService 加载了
AService 加载了
因为BService 的@Order(1),所以先打印出来
7、@WebFilter注解
8、@SpringBootTest注解
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.12.RELEASE</version>
<scope>test</scope>
</dependency>
代码
@RunWith(SpringRunner.class)
@SpringBootTest
public class servicesTest {
@Autowired
private CorpusInfoDAO corpusInfoDAO;
@Test
public void listPrivateCorpus() {
List<Byte> statusList = new ArrayList<>();
statusList.add((byte) 0);
statusList.add((byte) 1);
List<CorpusInfoDO> list = corpusInfoDAO.list("36013", statusList, (byte) 0);
System.out.println(list);
}
}