spring中常用的注解以及作用 - @RequestMapping

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力2027 👁️ 214 次阅读

在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

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧