5/22 18:26
This commit is contained in:
parent
2bcd1eb1f4
commit
9ba56b4d47
1
.idea/compiler.xml
generated
1
.idea/compiler.xml
generated
@ -7,6 +7,7 @@
|
|||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="printer-522work" />
|
||||||
<module name="spring519" />
|
<module name="spring519" />
|
||||||
<module name="spring-mybatis01-522" />
|
<module name="spring-mybatis01-522" />
|
||||||
<module name="mybatis519" />
|
<module name="mybatis519" />
|
||||||
|
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$/printer-522work/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/printer-522work/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/java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/spring-mybatis01-522/src/main/resources" 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" />
|
||||||
|
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -17,6 +17,7 @@
|
|||||||
<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" />
|
<option value="$PROJECT_DIR$/spring-mybatis01-522/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/printer-522work/pom.xml" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
32
printer-522work/pom.xml
Normal file
32
printer-522work/pom.xml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?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>printer-522work</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>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>5.3.23</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
29
printer-522work/src/main/java/cn/czyx007/bean/Printer.java
Normal file
29
printer-522work/src/main/java/cn/czyx007/bean/Printer.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package cn.czyx007.bean;
|
||||||
|
|
||||||
|
import cn.czyx007.dao.InkBox;
|
||||||
|
import cn.czyx007.dao.Paper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:19
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class Printer {
|
||||||
|
private InkBox inkBox;
|
||||||
|
private Paper paper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public Printer(InkBox inkBox, Paper paper){
|
||||||
|
this.inkBox = inkBox;
|
||||||
|
this.paper = paper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printDocument() {
|
||||||
|
System.out.println("开始打印...");
|
||||||
|
inkBox.print();
|
||||||
|
System.out.println("纸张大小:" + paper.getSize());
|
||||||
|
System.out.println("打印完成!");
|
||||||
|
}
|
||||||
|
}
|
9
printer-522work/src/main/java/cn/czyx007/dao/InkBox.java
Normal file
9
printer-522work/src/main/java/cn/czyx007/dao/InkBox.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package cn.czyx007.dao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:16
|
||||||
|
*/
|
||||||
|
public interface InkBox {
|
||||||
|
void print();
|
||||||
|
}
|
9
printer-522work/src/main/java/cn/czyx007/dao/Paper.java
Normal file
9
printer-522work/src/main/java/cn/czyx007/dao/Paper.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package cn.czyx007.dao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:16
|
||||||
|
*/
|
||||||
|
public interface Paper {
|
||||||
|
String getSize();
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.czyx007.dao.impl;
|
||||||
|
|
||||||
|
import cn.czyx007.dao.Paper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:17
|
||||||
|
*/
|
||||||
|
public class A4Paper implements Paper {
|
||||||
|
@Override
|
||||||
|
public String getSize() {
|
||||||
|
return "A4";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.czyx007.dao.impl;
|
||||||
|
|
||||||
|
import cn.czyx007.dao.Paper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:19
|
||||||
|
*/
|
||||||
|
public class B5Paper implements Paper {
|
||||||
|
@Override
|
||||||
|
public String getSize() {
|
||||||
|
return "B5";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.czyx007.dao.impl;
|
||||||
|
|
||||||
|
import cn.czyx007.dao.InkBox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:18
|
||||||
|
*/
|
||||||
|
public class ColorInkBox implements InkBox {
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
System.out.println("使用彩色墨盒打印");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cn.czyx007.dao.impl;
|
||||||
|
|
||||||
|
import cn.czyx007.dao.InkBox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:18
|
||||||
|
*/
|
||||||
|
public class GreyInkBox implements InkBox {
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
System.out.println("使用灰色墨盒打印");
|
||||||
|
}
|
||||||
|
}
|
19
printer-522work/src/main/resources/spring.xml
Normal file
19
printer-522work/src/main/resources/spring.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<!-- 配置墨盒和纸张的bean -->
|
||||||
|
<bean id="colorInkBox" class="cn.czyx007.dao.impl.ColorInkBox" />
|
||||||
|
<bean id="greyInkBox" class="cn.czyx007.dao.impl.GreyInkBox" />
|
||||||
|
<bean id="a4Paper" class="cn.czyx007.dao.impl.A4Paper" />
|
||||||
|
<bean id="b5Paper" class="cn.czyx007.dao.impl.B5Paper" />
|
||||||
|
|
||||||
|
<!-- 配置打印机的bean -->
|
||||||
|
<bean id="printer" class="cn.czyx007.bean.Printer">
|
||||||
|
<!-- 通过依赖注入组装打印机 -->
|
||||||
|
<constructor-arg ref="colorInkBox" />
|
||||||
|
<constructor-arg ref="a4Paper" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
</beans>
|
18
printer-522work/src/test/java/TestPrinter.java
Normal file
18
printer-522work/src/test/java/TestPrinter.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import cn.czyx007.bean.Printer;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/22 - 18:23
|
||||||
|
*/
|
||||||
|
public class TestPrinter {
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
//在spring配置文件spring.xml中通过依赖注入组装打印机
|
||||||
|
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
|
||||||
|
Printer printer = context.getBean("printer", Printer.class);
|
||||||
|
printer.printDocument();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user