From 7f23a964c08f26c409197a3207abde981dc84f2f Mon Sep 17 00:00:00 2001
From: zyx <1029606625@qq.com>
Date: Mon, 22 May 2023 14:34:21 +0800
Subject: [PATCH] 5/22 14:34
---
.idea/compiler.xml | 1 +
.idea/encodings.xml | 2 ++
.idea/misc.xml | 1 +
spring-mybatis01-522/pom.xml | 17 +++++++++++++++++
.../src/main/java/cn/czyx007/bean/User.java | 5 +++++
.../cn/czyx007/dao/impl/MysqlUserDaoImpl.java | 4 +++-
.../czyx007/service/impl/UserServiceImpl.java | 3 ++-
.../src/test/java/TestDemo.java | 7 +++++++
8 files changed, 38 insertions(+), 2 deletions(-)
create mode 100644 spring-mybatis01-522/pom.xml
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);
+ }
}