Annotation
스프링에서는 다양한 어노테이션(Annotation)을 제공하여 애플리케이션의 개발과 설정을 간소화 할 수 있다. 어노테이션들은 의존성 주입 , 트랜잭션 관리 등 스프링의 다양한 기능들을 설정하기 위해서 사용된다.
@Component
public class MyComponent{
componete logic
}
@Controller
public class MyComponent{
Request handling methods
}
@Service
public class MyService {
Service logic
}
@Repository
public class MyRepository {
Data access methods
}
@Service
public class MyService {
private MyRepository myRepository;
@Autowired
private MemberDao memberDao;
// Service methods here
}
@Controller
public class MyController {
@RequestMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
@Controller
public class MyController {
@RequestMapping("/search")
public String search(@RequestParam("keyword") String keyword) {
// Perform search based on the keyword
return "Search result: " + keyword;
}
}
@Controller
public class MyController {
@RequestMapping("/user/{id}")
@ResponseBody
public User getUser(@PathVariable("id") int userId) {
// Get user by ID
return user;
}
}
😊 어노테이션은 특정한 목적을 가지고 스프링 애플리케이션의 다양한 측면을 설정하고 관리하는데 도움을 준다!