公布一个自己写的Spring2.5中文教程,希望对需要的朋友有帮助

发布一个自己写的Spring2.5中文教程,希望对需要的朋友有帮助。

 

本文原文地址:http://www.blogjava.net/cmzy/archive/2008/08/03/219688.html 

暑假无聊的很,也找不到什么中意的兼职,米事就写写东西。本来准备写成一本书的,但是到现在也没一个详细的计划,甚至书名也没定,就是Spring的东西吧。再说也要毕业了,不知道能坚持到多久,尽力把它写完。不求有多么高级,只是希望可以总结一下自己以前学的东西,写出来,希望对需要的朋友有点帮助、同时也可以得到大侠们的帮助,使我进步:-)。

开发环境是MyEclipse6.5+Spring2.5,里面介绍了一些Spring2.5的新特性,现在刚刚把IoC写完,正准备写AOP的……现在把它放出来,内容只是涉及到SpringIOC的部分,博大伙儿一笑。

下载:Spring2.5中文简明教程

声明一下,本人的“正规”专业不是计算机,水平非常有限,所以书中难免有错误和疏漏之处,欢迎大家指正,我感激不尽,email是dashoumail@163.com 。

 

 

      另外,我博客上的大部分文章也是截取这本书上面的…………

1 楼 levyliu 2008-08-24  
<?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-2.0.xsd">


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/training">
</property>
<property name="username" value="root"></property>
<property name="password" value="219005"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>vo/User.hbm.xml</value></list>
</property></bean>
<bean id="UserDAO" class="vo.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory"></ref>
</property>
</bean>
    <bean id="service" class="service.Service">
    <property name="userDao">
    <ref bean="UserDAO"/>
    </property>
     </bean>
    <bean name="/login" class="web.action.LoginAction">
   <property name="service">
   <ref bean="service"/>
   </property>
    </bean>

</beans>
**************************************************************************
package service;

import java.util.List;

import vo.User;
import vo.UserDAO;

public class Service {

private UserDAO userDao;
public UserDAO getUserDao() {
return userDao;
}
public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
}
public boolean isValid(User user) {//判断用户是否合法
        List result = userDao.findByExample(user);
if (result.size() > 0)
return true;
else
return false;
}
}

***************************************************************
package vo;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
* Data access object (DAO) for domain model class User.
*
* @see vo.User
* @author MyEclipse Persistence Tools
*/

public class UserDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(UserDAO.class);

// property constants
public static final String NAME = "name";

public static final String PASSWORD = "password";

protected void initDao() {
// do nothing
}

public void save(User transientInstance) {
log.debug("saving User instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}

public void delete(User persistentInstance) {
log.debug("deleting User instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}

public User findById(java.lang.Integer id) {
log.debug("getting User instance with id: " + id);
try {
User instance = (User) getHibernateTemplate().get("vo.User", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}

public List findByExample(User instance) {
log.debug("finding User instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}

public List findByProperty(String propertyName, Object value) {
log.debug("finding User instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from User as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}

public List findByName(Object name) {
return findByProperty(NAME, name);
}

public List findByPassword(Object password) {
return findByProperty(PASSWORD, password);
}

public List findAll() {
log.debug("finding all User instances");
try {
String queryString = "from User";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}

public User merge(User detachedInstance) {
log.debug("merging User instance");
try {
User result = (User) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}

public void attachDirty(User instance) {
log.debug("attaching dirty User instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}

public void attachClean(User instance) {
log.debug("attaching clean User instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}

public static UserDAO getFromApplicationContext(ApplicationContext ctx) {
return (UserDAO) ctx.getBean("UserDAO");
}
}
*********************************************************************
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
**********************************
2 楼 levyliu 2008-08-24  
import javax.persistence.CascadeType;  
import javax.persistence.Column;  
import javax.persistence.Entity;  
import javax.persistence.FetchType;  
import javax.persistence.GeneratedValue;  
import javax.persistence.Id;  
import javax.persistence.OneToMany;  
import javax.persistence.Table;  
import javax.persistence.Temporal;  
import javax.persistence.TemporalType;  
  
import org.hibernate.annotations.Formula;  
import org.hibernate.annotations.GenericGenerator;  
  
@Entity  
@Table(name = "school_info")  
public class SchoolInfo implements java.io.Serializable {  
  
    @Id  
    @GeneratedValue(generator = "system-uuid")  
    @GenericGenerator(name = "system-uuid", strategy = "uuid")  
    private String id;//hibernate的uuid机制,生成32为字符串  
  
    @Column(name = "actcodeId", updatable = false, nullable = true, length = 36)  
    private String actcodeId;  
  
    @Formula("select COUNT(*) from school_info")  
    private int count;  
  
    @Temporal(TemporalType.TIMESTAMP)//不用set,hibernate会自动把当前时间写入  
    @Column(updatable = false, length = 20)  
    private Date createTime;  
  
    @Temporal(TemporalType.TIMESTAMP)  
    private Date updateTime;// 刚开始我默认insertable=false,但会读取出错提示如下:  
    // Value '0000-00-00' can not be represented as java.sql.Timestamp  
  
    // mappedBy="school"就相当于inverse=true,(mappedBy指定的是不需要维护关系的一端)  
    // 应该注意的是mappedBy值对应@ManyToOne标注的属性,我刚开始写成"schoolId",让我郁闷了好一会

    @OneToMany(mappedBy = "school", cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = UserMember.class)  
    // 用范性的话,就不用targetEntity了  
    private List users = new ArrayList();  
      
}  
************************************
@Entity  
@Table(name = "teacher_info")//实体类和数据库表名不一致时,才用这个  
public class UserMember implements java.io.Serializable {  
  
    @Id  
    @GeneratedValue(generator = "system-uuid")  
    @GenericGenerator(name = "system-uuid", strategy = "uuid")  
    private String id;  
  
    @Column(updatable = false, nullable = false, length = 20)  
    private String logonName;  
      
    @Temporal(TemporalType.TIMESTAMP)  
    @Column(updatable = false, length = 20)  
    private Date createTime;  
  
    @Temporal(TemporalType.TIMESTAMP)  
    private Date updateTime;  
  
    @ManyToOne(cascade = { CascadeType.MERGE })  
    @JoinColumn(name = "schoolId")  
    private SchoolInfo school;  
    //注意该类就不用声明schoolId属性了,如果不用@JoinColumn指明关联的字段,hibernate默认会是school_id.  
*******************************************
3 楼 levyliu 2008-08-24  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>JavaEye Java编程 Spring框架 AJAX技术 Agile敏捷软件开发 ruby on rails实践-JavaEye做最棒的软件开发交流社区</title>
    <meta name="description" content="Java编程,Spring Struts Webwork框架深入,XMLHTTP AJAX开发,Java Web开发,Java企业应用,Java设计模式,Java开源框架,Java应用服务器,Rich Client讨论,Ruby编程,Ruby DSL开发,Ruby on rails实践,JavaScript编程,敏捷软件开发XP TDD,软件配置管理,软件测试,项目管理UML,数据库,C#/.net C/C++ Erlang/FP PHP/Linux平台,精通Hibernate" />
    <meta name="keywords" content="Java编程 Spring框架 AJAX技术 Agile敏捷软件开发 ruby on rails实践 软件工程 讨论 论坛 JavaEye深度技术社区" />
    <link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon" />
    <link href="/rss/board/Java" rel="alternate" title="JavaEye论坛" type="application/rss+xml" />
    <link href="http://www.iteye.com/stylesheets/forum.css?1219503638" media="screen" rel="stylesheet" type="text/css" />
    <script src="http://www.iteye.com/javascripts/application.js?1214967926" type="text/javascript"></script>
      <link href="http://www.iteye.com/javascripts/syntaxhighlighter/SyntaxHighlighter.css?1201588027" media="screen" rel="stylesheet" type="text/css" />
  <script src="http://www.iteye.com/javascripts/syntaxhighlighter/shCoreCommon.js?1203397332" type="text/javascript"></script>
    <link href="http://www.iteye.com/javascripts/syntaxhighlighter/SyntaxHighlighter.css?1201588027" media="screen" rel="stylesheet" type="text/css" />
    <script src="http://www.iteye.com/javascripts/tinymce/tiny_mce.js?1207707663" type="text/javascript"></script>
<script src="http://www.iteye.com/javascripts/syntaxhighlighter/shCoreCommon.js?1203397332" type="text/javascript"></script>
  <link href="http://www.iteye.com/javascripts/editor/css/ui.css?1212551310" media="screen" rel="stylesheet" type="text/css" />
  <script src="http://www.iteye.com/javascripts/editor/compress.js?1217921045" type="text/javascript"></script>
  </head>
  <body>
    <div id="page">
      <div id="header" class="clearfix">
        <ul id="user_nav">
  <li class="last"><a href="/index/help">帮助</a></li>
    <li><a href="/logout">退出</a></li>   
    <li><a href="http://levyliu.iteye.com/admin/profile">设置</a></li>
    <li><a href="http://levyliu.iteye.com/admin/mygroups">我的圈子</a></li>
    <li><a href="http://levyliu.iteye.com/admin">我的博客</a></li>
      <li><a href="http://levyliu.iteye.com/admin/messages">收件箱 (0)</a></li>
    <li class='highlight'><span>欢迎 levyliu !</span></li>   
</ul>

       
        <div id="branding">
          <a href="http://www.iteye.com"><img alt="JavaEye3.0" src="http://www.iteye.com/images/logo.gif?1212054226" title="JavaEye-最棒的软件开发交流社区" /></a>
        </div> 
        <div id="ad">
          <embed width="720" height="60" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://ftp.iteye.com/public/ibm/bbs2.swf" play="true" loop="true" menu="true"></embed>
        </div>
      </div>
     
      <div id="content" class="clearfix">
        <div id="main">
         


         
<div class="crumbs">
  <a href="/forums">论坛首页</a> <span class="arrow">&rarr;</span>
  <a href="/forums/board/Java">Java</a> <span class="arrow">&rarr;</span>
  <a href="/topic/231814">发布一个自己写的Spring2.5中文教程,希望对需要的朋友有帮助。</a>
</div>

<form action="/forums/39/topics/231814/posts" enctype="multipart/form-data" id="editor_form" method="post">  <table id="forum_main" cellspacing="1">
    <thead>
      <tr>
        <td colspan="2">发表回复</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="row1">主题</td>
        <td class="row2">回复: 发布一个自己写的Spring2.5中文教程,希望对需要的朋友有帮助。</td>
      </tr>
      <tr>
        <td colspan="2" class="row3">
         
  <div id="editor_switch">
    <ul>
      <li><a href="#" id="editor_tab_bbcode" onclick="editor.switchMode('bbcode', true); return false;">BBCode编辑器</a></li>
      <li><a href="#" id="editor_tab_rich" onclick="editor.switchMode('rich', true); return false;">可视化编辑器</a></li>
      <li><a href="#" id="editor_tab_preview" onclick="editor.preview();; return false;">预览</a></li>
    </ul>
    <span id="editor_switch_spinner" style="padding-left: 5px; display: none;"><img alt="Spinner" src="http://www.iteye.com/images/spinner.gif?1182413454" /></span>
    <span id="editor_auto_save_update" style="padding-left: 5px;"></span>
  </div>
  <input type="hidden" name="auto_save_id" id="editor_auto_save_id"/>
  <div id="editor_preview" style="display:none;background-color:white;border:1px solid gray;padding:20px 5px;width:95%;overflow-x:auto;"></div>
  <input id="editor_bbcode_flag" name="post[bbcode]" type="hidden" value="true" />


<div id="editor_main"><textarea class="validate-richeditor bad-words min-length-5" cols="40" id="editor_body" name="post[body]" rows="20" style="width: 650px; height: 350px;"></textarea></div>

<script type="text/javascript">
  var editor = new Control.TextArea.Editor("editor_body", "bbcode", true);
</script>
        </td>
      </tr>
      <tr>
        <td class="row1">附件</td>
        <td class="row2"><ul>
  <li>上传文件请压缩后再上传,允许zip, rar, gz, tar, bz2, jar, war格式的压缩文件</li>
  <li>上传图片请使用JPG, JPEG, GIF, BMP, PNG格式</li>
  <li>最多上传三个附件, 单个文件大小不能超过5MB,附件总的大小不能超过10MB</li>
</ul>         
<input type="file" id="attachment_upload"/>
<script type="text/javascript">
  var multiple_upload_attachment_counter = 0;
  multiple_upload_attachment($("attachment_upload"), 3);
</script></td>
      </tr>
      <tr>
        <td colspan="2" align="center" class="row4"><input class="submit" id="submit_button" name="commit" type="submit" value="提交" /></td>
      </tr>
    </tbody>
  </table>
</form>
<div style="text-align:center; padding:20px 0 0 10px; text-align:center; font-weight:bold;">主题回顾</div>
<div style="height: 300px; overflow: auto">
  <table id="forum_main" cellspacing="1">
    <thead>
      <tr>
        <td>作者</td>
        <td>正文</td>
      </tr>
    </thead>
    <tbody>
      <tr>
      <td class="postauthor">
        <ul>
          <li class="name">cmzy</li>
        </ul>
      </td>
      <td class="postcontent">
        <p>&nbsp;&nbsp;&nbsp;&nbsp; <br />
<br />
暑假无聊的很,也找不到什么中意的兼职,米事就写写东西。本来准备写成一本书的,但是到现在也没一个详细的计划,甚至书名也没定,就是Spring的东西吧。再说也要毕业了,不知道能坚持到多久,尽力把它写完。不求有多么高级,只是希望可以总结一下自己以前学的东西,写出来,希望对需要的朋友有点帮助、同时也可以得到大侠们的帮助,使我进步:-)。<br />
<br />
开发环境是MyEclipse6.5+Spring2.5,里面介绍了一些Spring2.5的新特性,现在刚刚把IoC写完,正准备写AOP的&hellip;&hellip;现在把它放出来,内容只是涉及到SpringIOC的部分,博大伙儿一笑。<br />
<br />
下载:<a href="http://www.blogjava.net/Files/cmzy/Spring2.5Dev.pdf">Spring2.5中文简明教程</a>
&nbsp;&nbsp; <br /></p>
<p>
声明一下,本人的&ldquo;正规&rdquo;专业不是计算机,水平非常有限,所以书中难免有错误和疏漏之处,欢迎大家指正,我感激不尽,我的email是<a href="mailto:dashoumail@163.com">dashoumail@163.com</a>
。 </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; 另外,我博客上的大部分文章也是截取这本书上面的&hellip;&hellip;&hellip;&hellip;</p>
      </td>
    </tbody>
  </table>
</div>

<script type="text/javascript">
  new Validation("editor_form");
  dp.SyntaxHighlighter.ClipboardSwf = '/javascripts/syntaxhighlighter/clipboard.swf';
  dp.SyntaxHighlighter.HighlightAll('code', true, true);
</script>
        </div>
        <div id="nav">
<div class="wrapper">
<ul>
<li><a href="http://www.iteye.com/">首页</a></li>
<li><a href="http://www.iteye.com/news">新闻</a></li>
<li><a href="http://www.iteye.com/forums" class='selected'>论坛</a></li>
<li><a href="http://www.iteye.com/ask">问答</a></li>
<li><a href="http://www.iteye.com/wiki">知识库</a></li>
<li><a href="http://www.iteye.com/blogs">博客</a></li>
<li><a href="http://www.iteye.com/groups">圈子</a></li>
<li><a href="http://www.iteye.com/jobs">招聘</a></li>
<li><a href="http://www.iteye.com/index/service">服务</a></li>
<li class="last"><a href="http://www.iteye.com/search">搜索</a></li>
</ul>
</div>
</div>

<div id="channel_nav">
  <ul>
    <li><a href="http://java.iteye.com" >Java</a></li>
    <li><a href="http://ruby.iteye.com" >Ruby</a></li>
    <li><a href="http://ajax.iteye.com" >AJAX</a></li>
    <li><a href="http://agile.iteye.com" >敏捷</a></li>
    <li><a href="http://book.iteye.com" >图书</a></li>
    <li><a href="http://oracle.iteye.com" >Oracle</a></li>
    <li class="last"><a href="http://primeton.iteye.com" >普元</a></li>
  </ul>
</div>
      </div>
      <div id="footer">
  <div id="site_nav">
    <ul>
      <li><a href="/index/service">广告服务</a></li>
      <li><a href="http://webmaster.iteye.com">JavaEye黑板报</a></li>
      <li><a href="/index/sitemap">网站地图</a></li>
      <li><a href="/index/aboutus">关于我们</a></li>
      <li><a href="/index/contactus">联系我们</a></li>
      <li class="last"><a href="/index/friend_links">友情链接</a></li>
    </ul>
  </div>
  <div id="copyright">
    &copy; 2003-2008 iteye.com.   All rights reserved. 上海炯耐计算机软件有限公司 [ 沪ICP备05023328号 ]
  </div>
</div>     
    </div>
  </body>
 
</html>