欢迎来到天天文库
浏览记录
ID:40556827
大小:27.10 KB
页数:7页
时间:2019-08-04
《java Spring注解入门》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、JavaSpring注解入门1.使用Spring注解来注入属性1.1.使用注解以前我们是怎样注入属性的类的实现:Java代码1.public class UserManagerImpl implements UserManager { 2. private UserDao userDao; 3. public void setUserDao(UserDao userDao) { 4. this.userDao = userDao; 5. } 6. ... 7.} publicclassUserManagerIm
2、plimplementsUserManager{privateUserDaouserDao;publicvoidsetUserDao(UserDaouserDao){this.userDao=userDao;}...}配置文件:Java代码1. 2. 3. 4.3、"userDao" class="com.kedacom.spring.annotation.persistence.UserDaoImpl"> 5. 6. 4、eanid="userDao"class="com.kedacom.spring.annotation.persistence.UserDaoImpl">1.2.引入@Autowired注解(不推荐使用,建议使用@Resource)类的实现(对成员变量进行标注)Java代码1.public class UserManagerImpl implements UserManager { 2. @Autowired 3. priva5、te UserDao userDao; 4. ... 5.} publicclassUserManagerImplimplementsUserManager{@AutowiredprivateUserDaouserDao;...}或者(对方法进行标注)Java代码1.public class UserManagerImpl implements UserManager { 2. private UserDao userDao; 1. @Autowired 2. public void setUserDao(UserDao us6、erDao) { 3. this.userDao = userDao; 4. } 5. ... 6.} publicclassUserManagerImplimplementsUserManager{privateUserDaouserDao;@AutowiredpublicvoidsetUserDao(UserDaouserDao){this.userDao=userDao;}...}配置文件Java代码1.7、tion.service.UserManagerImpl" /> 2. 3. 4. <8、beanid="user
3、"userDao" class="com.kedacom.spring.annotation.persistence.UserDaoImpl"> 5. 6.
4、eanid="userDao"class="com.kedacom.spring.annotation.persistence.UserDaoImpl">1.2.引入@Autowired注解(不推荐使用,建议使用@Resource)类的实现(对成员变量进行标注)Java代码1.public class UserManagerImpl implements UserManager { 2. @Autowired 3. priva
5、te UserDao userDao; 4. ... 5.} publicclassUserManagerImplimplementsUserManager{@AutowiredprivateUserDaouserDao;...}或者(对方法进行标注)Java代码1.public class UserManagerImpl implements UserManager { 2. private UserDao userDao; 1. @Autowired 2. public void setUserDao(UserDao us
6、erDao) { 3. this.userDao = userDao; 4. } 5. ... 6.} publicclassUserManagerImplimplementsUserManager{privateUserDaouserDao;@AutowiredpublicvoidsetUserDao(UserDaouserDao){this.userDao=userDao;}...}配置文件Java代码1.7、tion.service.UserManagerImpl" /> 2. 3. 4. <8、beanid="user
7、tion.service.UserManagerImpl" /> 2. 3. 4. <
8、beanid="user
此文档下载收益归作者所有