spring中常用的注解以及作用 - @RequestMapping
在Spring框架中,注解是一种强大的工具,它可以用来修改类的行为,而无需修改代码。本文将详细介绍Spring中常用的一些注解及其作用。
1. @Autowired
@Autowired@Autowired
@Autowired
private MyService myService;
MyServicemyService
2. @Component
@Component
@Component
public class MyClass { ... }
3. @Service
@Service@Component@Service
@Service
public class MyService { ... }
4. @Repository
@Repository@Component
@Repository
public class MyDao { ... }
5. @Controller
@Controller
@Controller
public class MyController { ... }
6. @RequestMapping 拼多多帮助力入口
@RequestMapping
@RequestMapping("/hello")
public String hello() { return "Hello World!"; }
hello()
7. @ConfigurationProperties(prefix = "app")
这个注解用于将配置文件中的属性绑定到一个bean上。例如:
@ConfigurationProperties(prefix = "app")
public class MyProperties { ... }
MyProperties