spring常用注解(未完待续)

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 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)