5/22 14:34
This commit is contained in:
parent
2ad7dbccfc
commit
7f23a964c0
1
.idea/compiler.xml
generated
1
.idea/compiler.xml
generated
@ -8,6 +8,7 @@
|
|||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="spring519" />
|
<module name="spring519" />
|
||||||
|
<module name="spring-mybatis01-522" />
|
||||||
<module name="mybatis519" />
|
<module name="mybatis519" />
|
||||||
<module name="spring522-annotation" />
|
<module name="spring522-annotation" />
|
||||||
<module name="spring522" />
|
<module name="spring522" />
|
||||||
|
2
.idea/encodings.xml
generated
2
.idea/encodings.xml
generated
@ -11,6 +11,8 @@
|
|||||||
<file url="file://$PROJECT_DIR$/mybatis517-518/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/mybatis517-518/src/main/resources" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/mybatis519/src/main/java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/mybatis519/src/main/java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/mybatis519/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/mybatis519/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/spring-mybatis01-522/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/spring-mybatis01-522/src/main/resources" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/spring519/src/main/java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/spring519/src/main/java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/spring519/src/main/resources" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/spring519/src/main/resources" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/spring522-annotation/src/main/java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/spring522-annotation/src/main/java" charset="UTF-8" />
|
||||||
|
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -16,6 +16,7 @@
|
|||||||
<option value="$PROJECT_DIR$/spring519/pom.xml" />
|
<option value="$PROJECT_DIR$/spring519/pom.xml" />
|
||||||
<option value="$PROJECT_DIR$/spring522/pom.xml" />
|
<option value="$PROJECT_DIR$/spring522/pom.xml" />
|
||||||
<option value="$PROJECT_DIR$/spring522-annotation/pom.xml" />
|
<option value="$PROJECT_DIR$/spring522-annotation/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/spring-mybatis01-522/pom.xml" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
17
spring-mybatis01-522/pom.xml
Normal file
17
spring-mybatis01-522/pom.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>spring-mybatis01-522</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
@ -3,6 +3,8 @@ package cn.czyx007.bean;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : 张宇轩
|
* @author : 张宇轩
|
||||||
@ -11,8 +13,11 @@ import lombok.NoArgsConstructor;
|
|||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Component
|
||||||
public class User {
|
public class User {
|
||||||
private String id;
|
private String id;
|
||||||
|
//注意是spring包下的,不是lombok的
|
||||||
|
@Value("xxx")
|
||||||
private String userName;
|
private String userName;
|
||||||
private String address;
|
private String address;
|
||||||
private Integer age;
|
private Integer age;
|
||||||
|
@ -8,7 +8,9 @@ import org.springframework.stereotype.Repository;
|
|||||||
* @author : 张宇轩
|
* @author : 张宇轩
|
||||||
* @createTime : 2023/5/22 - 9:36
|
* @createTime : 2023/5/22 - 9:36
|
||||||
*/
|
*/
|
||||||
@Repository(value = "mysqlUserDao")
|
//@Repository(value = "mysqlUserDao")
|
||||||
|
//value默认为类名的小驼峰写法
|
||||||
|
@Repository
|
||||||
public class MysqlUserDaoImpl implements UserDao {
|
public class MysqlUserDaoImpl implements UserDao {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,7 +17,8 @@ public class UserServiceImpl implements UserService {
|
|||||||
//自动注入
|
//自动注入
|
||||||
@Autowired
|
@Autowired
|
||||||
//指定使用哪一个dao
|
//指定使用哪一个dao
|
||||||
@Qualifier("mysqlUserDao")
|
@Qualifier("mysqlUserDaoImpl")
|
||||||
|
// @Resource
|
||||||
UserDao userDao;
|
UserDao userDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,4 +16,11 @@ public class TestDemo {
|
|||||||
User user = userService.findUserById("1");
|
User user = userService.findUserById("1");
|
||||||
System.out.println("user = " + user);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user