spring是个啥玩儿意

来源:互联网 发布:仿淘宝 编辑:程序博客网 时间:2024/04/30 22:53

java里面那么多东西,真是让人眼花缭乱。比如spring。

我对spring的理解

1. spring是个框架。

2. 如何用呢,我搜索到了个小例子,但我从这个小例子看不出spring的作用:我的第一个spring学习——用myeclipse开发spring

我的第一个spring学习——用myeclipse开发spring

认为真正的程序开发员应该是大部分都用快捷的。以前,很多次java后我师问题时,他是"啪啪啪"地代跳那,看得我眼花缭乱当时,我就慕死了,心想:以后我也要这样
在,然我还没有到他那的水平,但是我用快捷
下面就用到一些常到的快捷

  ctrl+a:

  ctrl+c:

  ctrl+v:

我常用的有shift/Home/End+上下左右
大家有些常用的快捷键啊大家分享分享

Myeclipse不熟悉却要用它来开发spring的初学者来,是比有困的,因我就是这样过来的。所以,我做了个flash演示目的 ,但是太大了,上不了。于我注册blogjava的新手来,有些功能不太清楚。在我先把写下来,等以后我有时间把 blogjava弄明白了,看能不能再把那个flash上传上来。

步骤:

第一步:建工程
   File -> New -> Project ->Web Project,"Project Name":MySpringTest,
然后"Finish";

第二步:导入spring包
   
选中MySpringTest,右击,MyEclipse -> Add Spring Capabilities……,都默认即可;

第三步:
   
建立项目所需类;MySpringTest -> src -> New ...(以下三个都这样建)

Spring 
的开发没法自动生成 Bean, 这里大家只好手工来写了, 也很简单。

1
、接口Action:(MySpringTest -> src -> New -> interface ,取名为Action)

public interface Action {
    
public String execute(String str);
}

2、实现接口Action的类UpperAction:将其 message 属性与输入字符串相连接,并返回其大写形式。

   (MySpringTest -> src -> New -> class ,取名为UpperAction
 1 
 2 public class UpperAction implements Action{
 3     private String message;
 4 
 5     public String getMessage() {
 6         return message;
 7     }
 8 
 9     public void setMessage(String message) {
10         this.message = message;
11     }
12     public String execute(String str){
13         return (getMessage()+str).toUpperCase();
14     }
15 }
16 

3、实现接口Action的类LowerAction:

将其 message 属性与输入字符串相连接,并返回其小写形式。
   (MySpringTest -> src -> New -> class ,取名为LowerAction

 1 
 2 public class LowerAction implements Action{
 3     private String message;
 4 
 5     public String getMessage() {
 6         return message;
 7     }
 8     public void setMessage(String message) {
 9         this.message = message;
10     }
11     public String execute(String str){
12         return(getMessage()+str).toLowerCase();
13     }
14 }
15 

4、做测试用的SimpleTest类:
MySpringTest -> src -> New -> class ,取名为SimpleTest

 1 import org.springframework.context.ApplicationContext;
 2 import org.springframework.context.support.FileSystemXmlApplicationContext;
 3 
 4 public class SimpleTest {
 5     public static void main(String args[])
 6     {
 7         SimpleTest test=new SimpleTest();
 8         test.testQuickStart();
 9     }
10     public void testQuickStart(){
11         ApplicationContext ctx=new FileSystemXmlApplicationContext("src/bean.xml");
12         Action action=(Action)ctx.getBean("action1");
13         System.out.println(action.execute("Rod Johnson"));
14         action=(Action)ctx.getBean("action2");
15         System.out.println(action.execute("jeckj"));
16     }
17 }
18 

第四步:配置applicationContext.xml文件

 1      <?xml version="1.0" encoding="UTF-8"?>
 2      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 3      <beans>
 4      <description>Spring Quick Start</description>
 5      
 6      <!--该处bean中的name值必须是 其对应的class中的私有成员名
 7      -->
 8      <bean id="action1" class="UpperAction">
 9      <property name="message"> 
10      <value>HeLLo</value> 
11      </property> 
12      </bean>
13        
14      <bean id="action2" class="LowerAction">
15      <property name="message"> 
16      <value>HeLLo</value> 
17      </property> 
18      </bean> 
19      
20      </beans>

 第四步:调试
   双击 Package Explorer 下 MySpringTest/src/TestAction.java 打开源代码,点击菜单 Run -> Run As -> 1. Java Application, 如果没有错误的话将会出现如下

1 log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
2 log4j:WARN Please initialize the log4j system properly.
3 HELLOROD JOHNSON
4 hellojeckj