Java - Springboot

2021-02-16 09:20

阅读:476

标签: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 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


评论


亲,登录后才可以留言!