在项目中应用Spring框架技术.docVIP

  • 9
  • 0
  • 约7.97千字
  • 约 17页
  • 2017-08-26 发布于重庆
  • 举报
在项目中应用Spring框架技术.doc

MyEclipse 在Eclipse 中创建Spring的J2SE的应用 1、在Eclipse中新建一个J2SE 的 Project (1)名称为SpringJ2SEApp 输入项目的名称 最后产生出下面的结果 2、在该项目中添加一个应用程序的主类------它代表我们的客户程序 (1)类名称为SpringIoCClientApp,包名称为com.px1987.sshwebcrm.action (2)编程该类 package com.px1987.sshwebcrm.action; public class SpringIoCClientApp { public SpringIoCClientApp() { } public static void main(String[] args) { new SpringIoCClientApp(); } } 3、构建基于Spring的IoC容器管理的业务功能类代码——完成对“字符串的转换” (1)添加一个接口TransferAction,包名称为com.px1987.sshwebcrm.model 该TransferAction接口定义了一个doTransfer方法,在我们示例中,不同的TransferAction实现提供了各自的doTransfer方法,以完成目标逻辑处理的功能。 (2)编程该接口 package com.px1987.sshwebcrm.model; public interface TransferAction{ public String doTransfer(String inputStr); public void setMessageProperty(String messageProperty); } (3)为什么要面向接口编程而不是利用继承 因为,继承是一种强的耦合关系,子类对父类有很大的可见性,即子类可以使用父类的方法阿,字段什么的,所以当父类变化时,势必对子类有影响。 (4)添加对该TransferAction接口的两个不同实现类----UpperTransferAction类,包名称为com.px1987.sshwebcrm.model.imple (5)提供属性定义,并提供set方法 private String messageProperty; (6)编程该实现类 UpperTransferActionAction将其messageProperty属性与输入字符串相连接,并返回其大写形式。 package com.px1987.sshwebcrm.model.imple; import com.px1987.sshwebcrm.model.TransferAction; public class UpperTransferAction implements TransferAction { private String messageProperty; public String getMessageProperty() { return messageProperty; } public void setMessageProperty(String messageProperty) { this.messageProperty = messageProperty; } public UpperTransferAction() { } @Override public String doTransfer(String inputStr) { return (getMessageProperty() + inputStr).toUpperCase(); } } (6)添加对该TransferAction接口的两个实现类----LowerTransferAction类,包名称为com.px1987.sshwebcrm.model.imple (7)提供属性定义,并提供set方法 private String messageProperty; (8)编程该实现类,LowerAction将其message属性与输入字符串相连接,并返回其小写形式。 package com.px1987.sshwebcrm.model.imple; import com.px1987.sshwebcrm.model.TransferAction; public class LowerTransferAction implements TransferAction{ private String messageProperty; public LowerTransferAction (){ } public

文档评论(0)

1亿VIP精品文档

相关文档