From 9ba56b4d472f3a4017a18f0fc2b387f3ba7b0f6e Mon Sep 17 00:00:00 2001
From: zyx <1029606625@qq.com>
Date: Mon, 22 May 2023 18:27:03 +0800
Subject: [PATCH] 5/22 18:26
---
.idea/compiler.xml | 1 +
.idea/encodings.xml | 2 ++
.idea/misc.xml | 1 +
printer-522work/pom.xml | 32 +++++++++++++++++++
.../main/java/cn/czyx007/bean/Printer.java | 29 +++++++++++++++++
.../src/main/java/cn/czyx007/dao/InkBox.java | 9 ++++++
.../src/main/java/cn/czyx007/dao/Paper.java | 9 ++++++
.../java/cn/czyx007/dao/impl/A4Paper.java | 14 ++++++++
.../java/cn/czyx007/dao/impl/B5Paper.java | 14 ++++++++
.../java/cn/czyx007/dao/impl/ColorInkBox.java | 14 ++++++++
.../java/cn/czyx007/dao/impl/GreyInkBox.java | 14 ++++++++
printer-522work/src/main/resources/spring.xml | 19 +++++++++++
.../src/test/java/TestPrinter.java | 18 +++++++++++
13 files changed, 176 insertions(+)
create mode 100644 printer-522work/pom.xml
create mode 100644 printer-522work/src/main/java/cn/czyx007/bean/Printer.java
create mode 100644 printer-522work/src/main/java/cn/czyx007/dao/InkBox.java
create mode 100644 printer-522work/src/main/java/cn/czyx007/dao/Paper.java
create mode 100644 printer-522work/src/main/java/cn/czyx007/dao/impl/A4Paper.java
create mode 100644 printer-522work/src/main/java/cn/czyx007/dao/impl/B5Paper.java
create mode 100644 printer-522work/src/main/java/cn/czyx007/dao/impl/ColorInkBox.java
create mode 100644 printer-522work/src/main/java/cn/czyx007/dao/impl/GreyInkBox.java
create mode 100644 printer-522work/src/main/resources/spring.xml
create mode 100644 printer-522work/src/test/java/TestPrinter.java
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index c3592de..7c85ad5 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,7 @@
+
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index d3e3763..5dc4174 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -11,6 +11,8 @@
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d9c501b..54cb61e 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -17,6 +17,7 @@
+
diff --git a/printer-522work/pom.xml b/printer-522work/pom.xml
new file mode 100644
index 0000000..c9e7141
--- /dev/null
+++ b/printer-522work/pom.xml
@@ -0,0 +1,32 @@
+
+
+ 4.0.0
+
+ org.example
+ printer-522work
+ 1.0-SNAPSHOT
+
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+ org.springframework
+ spring-context
+ 5.3.23
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+
+
+
\ No newline at end of file
diff --git a/printer-522work/src/main/java/cn/czyx007/bean/Printer.java b/printer-522work/src/main/java/cn/czyx007/bean/Printer.java
new file mode 100644
index 0000000..54ca7d7
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/bean/Printer.java
@@ -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("打印完成!");
+ }
+}
diff --git a/printer-522work/src/main/java/cn/czyx007/dao/InkBox.java b/printer-522work/src/main/java/cn/czyx007/dao/InkBox.java
new file mode 100644
index 0000000..ea97b8a
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/dao/InkBox.java
@@ -0,0 +1,9 @@
+package cn.czyx007.dao;
+
+/**
+ * @author : 张宇轩
+ * @createTime : 2023/5/22 - 18:16
+ */
+public interface InkBox {
+ void print();
+}
diff --git a/printer-522work/src/main/java/cn/czyx007/dao/Paper.java b/printer-522work/src/main/java/cn/czyx007/dao/Paper.java
new file mode 100644
index 0000000..c9fe216
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/dao/Paper.java
@@ -0,0 +1,9 @@
+package cn.czyx007.dao;
+
+/**
+ * @author : 张宇轩
+ * @createTime : 2023/5/22 - 18:16
+ */
+public interface Paper {
+ String getSize();
+}
diff --git a/printer-522work/src/main/java/cn/czyx007/dao/impl/A4Paper.java b/printer-522work/src/main/java/cn/czyx007/dao/impl/A4Paper.java
new file mode 100644
index 0000000..d3825bd
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/dao/impl/A4Paper.java
@@ -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";
+ }
+}
diff --git a/printer-522work/src/main/java/cn/czyx007/dao/impl/B5Paper.java b/printer-522work/src/main/java/cn/czyx007/dao/impl/B5Paper.java
new file mode 100644
index 0000000..3fa0a3e
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/dao/impl/B5Paper.java
@@ -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";
+ }
+}
diff --git a/printer-522work/src/main/java/cn/czyx007/dao/impl/ColorInkBox.java b/printer-522work/src/main/java/cn/czyx007/dao/impl/ColorInkBox.java
new file mode 100644
index 0000000..5408946
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/dao/impl/ColorInkBox.java
@@ -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("使用彩色墨盒打印");
+ }
+}
diff --git a/printer-522work/src/main/java/cn/czyx007/dao/impl/GreyInkBox.java b/printer-522work/src/main/java/cn/czyx007/dao/impl/GreyInkBox.java
new file mode 100644
index 0000000..740365a
--- /dev/null
+++ b/printer-522work/src/main/java/cn/czyx007/dao/impl/GreyInkBox.java
@@ -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("使用灰色墨盒打印");
+ }
+}
diff --git a/printer-522work/src/main/resources/spring.xml b/printer-522work/src/main/resources/spring.xml
new file mode 100644
index 0000000..2783636
--- /dev/null
+++ b/printer-522work/src/main/resources/spring.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/printer-522work/src/test/java/TestPrinter.java b/printer-522work/src/test/java/TestPrinter.java
new file mode 100644
index 0000000..28388ae
--- /dev/null
+++ b/printer-522work/src/test/java/TestPrinter.java
@@ -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();
+ }
+}