diff --git a/ffms-SpringProject/ffms-SpringProject.iml b/ffms-SpringProject/ffms-SpringProject.iml index 98b2e3e..3078e4f 100644 --- a/ffms-SpringProject/ffms-SpringProject.iml +++ b/ffms-SpringProject/ffms-SpringProject.iml @@ -7,6 +7,7 @@ - + + \ No newline at end of file diff --git a/ffms-SpringProject/src/bean-di-annotation.xml b/ffms-SpringProject/src/bean-di-annotation.xml index 3329e39..2b00cf7 100644 --- a/ffms-SpringProject/src/bean-di-annotation.xml +++ b/ffms-SpringProject/src/bean-di-annotation.xml @@ -1,13 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/ffms-SpringProject/src/bean-di-xml.xml b/ffms-SpringProject/src/bean-di-xml.xml new file mode 100644 index 0000000..e2cae49 --- /dev/null +++ b/ffms-SpringProject/src/bean-di-xml.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/Budget.java b/ffms-SpringProject/src/com/ssm/di/annotation/Budget.java new file mode 100644 index 0000000..63bb9e7 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/Budget.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class Budget { + @Value("5001") + private Integer budgetId; + @Value("月度预算") + private String budgetName; + @Override + public String toString() { + return "Budget{budgetId=" + budgetId + ", budgetName='" + budgetName + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/DataDict.java b/ffms-SpringProject/src/com/ssm/di/annotation/DataDict.java new file mode 100644 index 0000000..637d9b5 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/DataDict.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class DataDict { + @Value("7001") + private Integer dictId; + @Value("收支类型") + private String dictType; + @Override + public String toString() { + return "DataDict{dictId=" + dictId + ", dictType='" + dictType + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/Expense.java b/ffms-SpringProject/src/com/ssm/di/annotation/Expense.java new file mode 100644 index 0000000..346bf09 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/Expense.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class Expense { + @Value("2001") + private Integer expenseId; + @Value("餐饮支出") + private String expenseType; + @Override + public String toString() { + return "Expense{expenseId=" + expenseId + ", expenseType='" + expenseType + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/Income.java b/ffms-SpringProject/src/com/ssm/di/annotation/Income.java new file mode 100644 index 0000000..d9c5209 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/Income.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class Income { + @Value("1001") + private Integer incomeId; + @Value("工资收入") + private String incomeType; + @Override + public String toString() { + return "Income{incomeId=" + incomeId + ", incomeType='" + incomeType + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/Notice.java b/ffms-SpringProject/src/com/ssm/di/annotation/Notice.java new file mode 100644 index 0000000..f84a8c6 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/Notice.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class Notice { + @Value("6001") + private Integer noticeId; + @Value("系统通知") + private String noticeTitle; + @Override + public String toString() { + return "Notice{noticeId=" + noticeId + ", noticeTitle='" + noticeTitle + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/Product.java b/ffms-SpringProject/src/com/ssm/di/annotation/Product.java deleted file mode 100644 index 9a587f2..0000000 --- a/ffms-SpringProject/src/com/ssm/di/annotation/Product.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.ssm.di.annotation; - -import org.springframework.stereotype.Component; - -@Component -public class Product { - private Integer pid = 2; - private String pname = "荷兰豆"; - private Double marketPrice = 12.9; - private Double shopPrice = 12.0; - private String image = "products/f4c77d4e-57ca-4f95-8b03"; - - @Override - public String toString() { - return "Product{" + - "pid=" + pid + - ", pname='" + pname + '\'' + - ", marketPrice=" + marketPrice + - ", shopPrice=" + shopPrice + - ", image='" + image + '\'' + - '}'; - } -} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/SecuritiesAccount.java b/ffms-SpringProject/src/com/ssm/di/annotation/SecuritiesAccount.java new file mode 100644 index 0000000..759fa0a --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/SecuritiesAccount.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class SecuritiesAccount { + @Value("3001") + private Integer accountId; + @Value("A股账户") + private String accountType; + @Override + public String toString() { + return "SecuritiesAccount{accountId=" + accountId + ", accountType='" + accountType + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/SpringConfig.java b/ffms-SpringProject/src/com/ssm/di/annotation/SpringConfig.java index 45fafb3..8f37c9a 100644 --- a/ffms-SpringProject/src/com/ssm/di/annotation/SpringConfig.java +++ b/ffms-SpringProject/src/com/ssm/di/annotation/SpringConfig.java @@ -1,9 +1,7 @@ package com.ssm.di.annotation; - import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; - @Configuration -@ComponentScan("com.ssm.di.annotation") +@ComponentScan(basePackages = "com.ssm.di.annotation") public class SpringConfig { } \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/StockHold.java b/ffms-SpringProject/src/com/ssm/di/annotation/StockHold.java new file mode 100644 index 0000000..bbda7b6 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/StockHold.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class StockHold { + @Value("4001") + private Integer holdId; + @Value("贵州茅台") + private String stockName; + @Override + public String toString() { + return "StockHold{holdId=" + holdId + ", stockName='" + stockName + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/Test.java b/ffms-SpringProject/src/com/ssm/di/annotation/Test.java deleted file mode 100644 index ea5a68d..0000000 --- a/ffms-SpringProject/src/com/ssm/di/annotation/Test.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.ssm.di.annotation; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class Test{ - public static void main(String[] args) { - ApplicationContext ac = new ClassPathXmlApplicationContext("bean-di-annotation.xml"); - Product product = (Product) ac.getBean("product"); - System.out.println(product.toString()); - } -} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java b/ffms-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java new file mode 100644 index 0000000..445b37c --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java @@ -0,0 +1,16 @@ +package com.ssm.di.annotation; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +public class TestAnnotation { + public static void main(String[] args) { + ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); + System.out.println(context.getBean(User.class)); + System.out.println(context.getBean(Income.class)); + System.out.println(context.getBean(Expense.class)); + System.out.println(context.getBean(SecuritiesAccount.class)); + System.out.println(context.getBean(StockHold.class)); + System.out.println(context.getBean(Budget.class)); + System.out.println(context.getBean(Notice.class)); + System.out.println(context.getBean(DataDict.class)); + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/annotation/User.java b/ffms-SpringProject/src/com/ssm/di/annotation/User.java new file mode 100644 index 0000000..4151ed9 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/annotation/User.java @@ -0,0 +1,14 @@ +package com.ssm.di.annotation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +@Component +public class User { + @Value("1") + private Integer userId; + @Value("admin") + private String username; + @Override + public String toString() { + return "User{userId=" + userId + ", username='" + username + "'}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/xml/Student.java b/ffms-SpringProject/src/com/ssm/di/xml/Student.java new file mode 100644 index 0000000..50728cd --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/xml/Student.java @@ -0,0 +1,28 @@ +package com.ssm.di.xml; + +public class Student { + private Integer id; + private String name; + private Integer age; + + public void setId(Integer id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setAge(Integer age) { + this.age = age; + } + + public void printInfo() { + System.out.println("学生信息:id=" + id + ", name=" + name + ", age=" + age); + } + + @Override + public String toString() { + return "Student{id=" + id + ", name='" + name + "', age=" + age + "}"; + } +} \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/xml/TestDI.java b/ffms-SpringProject/src/com/ssm/di/xml/TestDI.java new file mode 100644 index 0000000..b40ba15 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/xml/TestDI.java @@ -0,0 +1,14 @@ +package com.ssm.di.xml; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class TestDI { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("bean-di-xml.xml"); + Student student = (Student) context.getBean("student"); + + student.printInfo(); + System.out.println(student); + } +} \ No newline at end of file diff --git a/ffms/ffms.iml b/ffms/ffms.iml index 3bd0086..3078e4f 100644 --- a/ffms/ffms.iml +++ b/ffms/ffms.iml @@ -7,7 +7,7 @@ - + \ No newline at end of file