diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 908d72d..c3592de 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -8,6 +8,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 00d4fdc..d3e3763 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -11,6 +11,8 @@ + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 4dd72c6..d9c501b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -16,6 +16,7 @@ diff --git a/spring-mybatis01-522/pom.xml b/spring-mybatis01-522/pom.xml new file mode 100644 index 0000000..faf4483 --- /dev/null +++ b/spring-mybatis01-522/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + spring-mybatis01-522 + 1.0-SNAPSHOT + + + 11 + 11 + UTF-8 + + + \ No newline at end of file diff --git a/spring522-annotation/src/main/java/cn/czyx007/bean/User.java b/spring522-annotation/src/main/java/cn/czyx007/bean/User.java index 9ee6343..79c5afc 100644 --- a/spring522-annotation/src/main/java/cn/czyx007/bean/User.java +++ b/spring522-annotation/src/main/java/cn/czyx007/bean/User.java @@ -3,6 +3,8 @@ package cn.czyx007.bean; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; /** * @author : 张宇轩 @@ -11,8 +13,11 @@ import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor +@Component public class User { private String id; + //注意是spring包下的,不是lombok的 + @Value("xxx") private String userName; private String address; private Integer age; diff --git a/spring522-annotation/src/main/java/cn/czyx007/dao/impl/MysqlUserDaoImpl.java b/spring522-annotation/src/main/java/cn/czyx007/dao/impl/MysqlUserDaoImpl.java index f96d9f8..65fba16 100644 --- a/spring522-annotation/src/main/java/cn/czyx007/dao/impl/MysqlUserDaoImpl.java +++ b/spring522-annotation/src/main/java/cn/czyx007/dao/impl/MysqlUserDaoImpl.java @@ -8,7 +8,9 @@ import org.springframework.stereotype.Repository; * @author : 张宇轩 * @createTime : 2023/5/22 - 9:36 */ -@Repository(value = "mysqlUserDao") +//@Repository(value = "mysqlUserDao") +//value默认为类名的小驼峰写法 +@Repository public class MysqlUserDaoImpl implements UserDao { @Override diff --git a/spring522-annotation/src/main/java/cn/czyx007/service/impl/UserServiceImpl.java b/spring522-annotation/src/main/java/cn/czyx007/service/impl/UserServiceImpl.java index e6faea2..810f60a 100644 --- a/spring522-annotation/src/main/java/cn/czyx007/service/impl/UserServiceImpl.java +++ b/spring522-annotation/src/main/java/cn/czyx007/service/impl/UserServiceImpl.java @@ -17,7 +17,8 @@ public class UserServiceImpl implements UserService { //自动注入 @Autowired //指定使用哪一个dao - @Qualifier("mysqlUserDao") + @Qualifier("mysqlUserDaoImpl") +// @Resource UserDao userDao; @Override diff --git a/spring522-annotation/src/test/java/TestDemo.java b/spring522-annotation/src/test/java/TestDemo.java index 6bf499c..4d0fc94 100644 --- a/spring522-annotation/src/test/java/TestDemo.java +++ b/spring522-annotation/src/test/java/TestDemo.java @@ -16,4 +16,11 @@ public class TestDemo { User user = userService.findUserById("1"); System.out.println("user = " + user); } + + @Test + public void test2(){ + ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("spring.xml"); + User user = app.getBean("user", User.class); + System.out.println(user); + } }