码迷,mamicode.com
首页 > 编程语言 > 详细

Java - Springboot

时间:2020-04-15 21:09:34      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:record   注解   get   config   ali   vat   data   ble   统一   

注解

@SpringBootApplication:@Configuration + @EnableAutoConfiguration + @ComponentScan

  • @EnableAutoConfiguration:自动配置springboot
  • @ComponentScan:自动扫描和装配所有的Spring组件,包括@Configuration类
@SpringBootApplication
public class AfvappApplication {
	public static void main(String[] args) {
		SpringApplication.run(AfvappApplication.class, args);
	}
}

@Controller:类注解,控制器层,类中方法配合@RequestMapping
@RestController:类注解,控制器层,REST风格,@Controller + @ResponseBody

@RestController
@RequestMapping("/demo")
public class DemoController {
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello() { ... }
}

@Repository:确保DAO或者repositories提供异常转译

@Repository
public interface SqlserverMapper {
    List<String> listVerifyRecords();
}

@Qualifier:@Qualifier(“name”) + @Autowired
@Resource:

@Autowired
@Qualifier(value = "sqlserverDataSource")
private DataSource sqlserverDataSource;

@Resource(name = "yt_MATHandleServiceImpl")
private MATHandleService ytService;
@Resource(name = "cw_MATHandleServiceImpl")
private MATHandleService cwService;

全局异常处理
@ControllerAdvice:包含@Component,可以被扫描到,统一处理异常
@ExceptionHandler(Exception.class):方法注解,表示遇到该异常就执行以下方法

其他注解

@Service:类注解,服务层
@Component:泛指组件

Java - Springboot

标签:record   注解   get   config   ali   vat   data   ble   统一   

原文地址:https://www.cnblogs.com/wjcx-sqh/p/12708253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!