1.@Controller、@RestController、@RequestMapping注解。
@Controller:修饰class,用来创建处理http请求的对象
@RestController:Spring4之后加入的注解,原来在@Controller中返回json需要@ResponseBody来配合,如果直接用@RestController替代@Controller就
不需要再配置@ResponseBody,默认返回json格式。
@RequestMapping:配置url映射
2.@PostConstruct和@PreDestroy
这两个作用于Servlet生命周期的注解,实现Bean初始化之前和销毁之前的自定义操作。
@Autowired
Scheduler scheduler;
/**
* 项目启动时,初始化定时器
* @author lyd
* @date 2017年10月14日
*/
@PostConstruct
public void init() throws Exception {
List<ScheduleJobEntity> scheduleJobList = scheduleJobDao.queryList(new ScheduleJobQuery());
for (ScheduleJobEntity scheduleJob : scheduleJobList) {
CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getJobId());
//如果不存在,则创建
if(cronTrigger == null){
ScheduleUtils.createScheduleJob(scheduler, scheduleJob);
} else {
ScheduleUtils.updateScheduleJob(scheduler, scheduleJob);
}
}
}
本文详细介绍了Spring MVC框架中常用注解的功能与使用方法,包括@Controller、@RestController、@RequestMapping等HTTP请求处理注解,以及@PostConstruct和@PreDestroy两个用于定义Bean生命周期方法的注解。
955

被折叠的 条评论
为什么被折叠?



