@Repository注解ï¼
1 package imooc_spring.test.anotation.myrepository;
2
3 import org.springframework.stereotype.Repository;
4
5 /**
6 * æå®id,é»è®¤ä¸ºdAO,å³ç±»åé¦åæ¯å°åï¼å¦ææå®äºå称é£ä¹åªè½ctx.getBean(æå®å称)æ¥è·åbean
7 * è¿ä¸ªä¾åéå°±åªè½éè¿ctx.getBean("wyldao)æ¥è·åDAO çå®ä¾äº;
8 *
9 * @author Wei
10 */
11 @Repository("wyldao")
12 public class DAO {
13 /**
14 * è¿åxåyçä¹ç§¯
15 *
16 * @param x
17 * @param y
18 * @return x*y
19 */
20 public int multi(int x, int y) {
21 return x * y;
22 }
23 }
å¤å¶ä»£ç
@Component 注解ï¼
å¤å¶ä»£ç
1 package imooc_spring.test.anotation;
2
3 import org.springframework.stereotype.Component;
4 /**
5 * Component 注解
6 * @author Wei
7 *
8 */
9 @Component
10 public class TestObj {
11 public void SayHi(){
12 System.out.println("\nHi this is TestObj.SayHi()...");
13 }
14 }
å¤å¶ä»£ç
@Controller注解ï¼
å¤å¶ä»£ç
1 package imooc_spring.test.anotation;
2
3 import org.springframework.stereotype.Controller;
4
5 @Controller
6 public class UserController {
7 public void execute(){
8 System.out.println("\nUserController.execute()...");
9 }
10 }
å¤å¶ä»£ç
@Repository注解ï¼
å¤å¶ä»£ç
1 package imooc_spring.test.anotation;
2
3 import org.springframework.stereotype.Repository;
4
5 //@Repository
6 @Repository("wyl_repo")
7 public class UserRepositoryImpl implements IUserRepository {
8 //模ææä¹ åå±
9 @Override
10 public void save() {
11 // TODO Auto-generated method stub
12 System.out.println("\nUserRepositoryImpl.save()...");
13 }
14
15 }
å¤å¶ä»£ç
@Service注解ï¼
å¤å¶ä»£ç
1 package imooc_spring.test.anotation;
2
3 import org.springframework.stereotype.Service;
4
5 @Service
6 public class UserService {
7 public void add(){
8 System.out.println("\nUserService.add()...");
9 }
10 }