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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值