﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-软件艺术思考者-随笔分类-about spring</title><link>http://www.blogjava.net/zhanglijun33/category/17946.html</link><description>混沌，彷徨，立志，蓄势...</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 03:10:01 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 03:10:01 GMT</pubDate><ttl>60</ttl><item><title>spring 实践，进一步理解和使用aop</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/27/aoptest.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Thu, 27 Jul 2006 09:04:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/27/aoptest.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/60383.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/27/aoptest.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/60383.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/60383.html</trackback:ping><description><![CDATA[今天我彻底的理解了aop的概念及用法。比较起来还是概念比较重要，其实spring向我们展示的最重要的东西就是思维。她已经不是面向对象了，而是面向对象的集合--切面。<br />aop是面向切面编程的，由此首先应该弄清的是：什么是切面？<br />切面是切入点和通知的结合体。<br />怎样组织一个切面？换句话说怎么把众多的类组织成一个切面？就要看我们在哪些类的代理类中插入相同的通知了。过多的例子不再举了，如果谁想要一份testAOP工程实例，可以给我留言。<br />本程序说明：<br />tom是公司的一位经理manager（pojo）。<br />由于事务繁忙，他聘用了一个秘书secretary（通知），<br />每当经理上班的时候，秘书总会把一天的计划自动的提前交给经理并作口水状。<br />而对于别人，她的态度就不是那么好了。<br />在这个程序中，我们的秘书对经理说话的时候用的是前置通知。<br />对普通工人说话的时候用的是后置通知。<br />点一下运行看看程序的结果吧？<img src ="http://www.blogjava.net/zhanglijun33/aggbug/60383.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-27 17:04 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/27/aoptest.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SpringFramework中的AOP简单使用  </title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/aop.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Tue, 25 Jul 2006 03:38:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/aop.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/59957.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/aop.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/59957.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/59957.html</trackback:ping><description><![CDATA[
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td valign="top" align="left" width="100%">
										<div class="diaryTitleBg">SpringFramework中的AOP简单使用 </div>
								</td>
						</tr>
						<tr>
								<td valign="top" align="left" width="100%">
										<div class="diarybody">
												<div>AOP作为Spring这个轻量级的容器中很重要的一部分，得到越来越多的关注，Spring的Transaction就是用AOP来管理的，今天就通过简单的例子来看看Spring中的AOP的基本使用方法。 
<p>  首先确定将要Proxy的目标，在Spring中默认采用JDK中的dynamic proxy，它只能够实现接口的代理，如果想对类进行代理的话，需要采用CGLIB的proxy。显然，选择“编程到接口”是更明智的做法，下面是将要代理的接口：</p><p><font face="Courier New" color="#6655aa" size="2">  public interface FooInterface {<br />    public void printFoo();<br />    public void dummyFoo();<br />  }</font><br /> <br />  以及其一个简单的实现：<br /> <br /><font face="Courier New" color="#614db3" size="2">  public class FooImpl implements FooInterface {<br />    public void printFoo() {<br />      System.out.println("In FooImpl.printFoo");<br />    }<br />    public void dummyFoo() {<br />      System.out.println("In FooImpl.dummyFoo");<br />    }<br />  }</font><br /> <br />  接下来创建一个Advice，在Spring中支持Around,Before,After returning和Throws四种Advice，这里就以简单的Before Advice举例：<br /> <br /><font face="Courier New" color="#614db3" size="2">  public class PrintBeforeAdvice implements MethodBeforeAdvice {<br />    public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable {<br />      System.out.println("In PrintBeforeAdvice");<br />    }<br />  }<br /></font> <br />  有了自己的business interface和advice，剩下的就是如何去装配它们了，首先利用ProxyFactory以编程方式实现，如下：<br /> <br /><font face="Courier New" color="#614db3" size="2">  public class AopTestMain {<br />    public static void main(String[] args) {<br />      FooImpl fooImpl = new FooImpl();<br />      PrintBeforeAdvice myAdvice = new PrintBeforeAdvice();<br />     <br />      ProxyFactory factory = new ProxyFactory(fooImpl);<br />      factory.addBeforeAdvice(myAdvice);<br />      FooInterface myInterface = (FooInterface)factory.getProxy();</font></p><p><font face="Courier New" color="#614db3" size="2">      myInterface.printFoo();<br />      myInterface.dummyFoo();<br />    }<br />  }<br /></font> <br />  现在执行程序，神奇的结果就出现了：<br /> <br /><font face="Courier New" color="#614db3" size="2">  In PrintBeforeAdvice<br />  In FooImpl.printFoo<br />  In PrintBeforeAdvice<br />  In FooImpl.dummyFoo</font><br /> <br />  虽然这样能体会到Spring中AOP的用法，但这决不是值得推荐的方法，既然使用了Spring，在ApplicationContext中装配所需要 的bean才是最佳策略，实现上面的功能只需要写个简单的applicationContext就可以了，如下：<br /> <br /><font face="Courier New" color="#614db3" size="2">  &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"<br />    "</font><a href="http://www.springframework.org/dtd/spring-beans.dtd"><font face="Courier New" color="#614db3" size="2">http://www.springframework.org/dtd/spring-beans.dtd</font></a><font face="Courier New" color="#614db3" size="2">"&gt;</font></p><p><font face="Courier New" color="#614db3" size="2">  &lt;beans&gt;<br />    &lt;description&gt;The aop application context&lt;/description&gt;<br />    &lt;bean id="fooTarget" class="FooImpl"/&gt;<br />    &lt;bean id="myAdvice" class="PrintBeforeAdvice"/&gt;<br />    &lt;bean id="foo" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;<br />     &lt;property name="proxyInterfaces"&gt;<br />       &lt;value&gt;FooInterface&lt;/value&gt;<br />     &lt;/property&gt;<br />     &lt;property name="target"&gt;<br />       &lt;ref local="fooTarget"/&gt;<br />     &lt;/property&gt;<br />     &lt;property name="interceptorNames"&gt;<br />       &lt;list&gt;<br />         &lt;value&gt;myAdvice&lt;/value&gt;<br />       &lt;/list&gt;<br />     &lt;/property&gt;<br />    &lt;/bean&gt;<br />  &lt;/beans&gt;</font></p><p>  当然，main中的代码也要进行相应的修改：<br />    <br /><font face="Courier New" color="#614db3" size="2">  public static void main(String[] args) {<br />    ClassPathXmlApplicationContext context = new <br />             ClassPathXmlApplicationContext("applicationContext.xml");<br />    FooInterface foo = (FooInterface)context.getBean("foo");<br />    foo.printFoo();<br />    foo.dummyFoo();<br />  }</font><br /> <br />  现在运行一下，结果将和上面的运行结果完全一样，这样是不是更优雅？当需要更改实现时，只需要修改配置文件就可以了，程序中的代码不需任何改动。<br /> <br />  但是，这时候会发现被proxy的object中的所有方法调用时都将运行advice中的before，这显然不能满足绝大多数情况下的需要，此时，只 需借用Advisor就可以了，当然要在Advisor中利用pattern设置好哪些方法需要advice，更改applicationContext 如下：<br /> <br /><font face="Courier New" color="#614db3" size="2">  &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"<br />    "</font><a href="http://www.springframework.org/dtd/spring-beans.dtd"><font face="Courier New" color="#614db3" size="2">http://www.springframework.org/dtd/spring-beans.dtd</font></a><font face="Courier New" color="#614db3" size="2">"&gt;</font></p><p><font face="Courier New" color="#614db3" size="2">  &lt;beans&gt;<br />    &lt;description&gt;The springeva application context&lt;/description&gt;<br />    &lt;bean id="fooTarget" class="FooImpl"/&gt;<br />    &lt;bean id="printBeforeAdvice" class="PrintBeforeAdvice"/&gt;<br />    &lt;bean id="myAdvisor"<br />          class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"&gt;<br />      &lt;property name="advice"&gt;<br />        &lt;ref local="printBeforeAdvice"/&gt;<br />      &lt;/property&gt;<br />      &lt;property name="pattern"&gt;<br />        &lt;value&gt;.*print.*&lt;/value&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />    &lt;bean id="foo" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;<br />      &lt;property name="proxyInterfaces"&gt;<br />        &lt;value&gt;FooInterface&lt;/value&gt;<br />      &lt;/property&gt;<br />      &lt;property name="target"&gt;<br />        &lt;ref local="fooTarget"/&gt;<br />      &lt;/property&gt;<br />      &lt;property name="interceptorNames"&gt;<br />        &lt;list&gt;<br />          &lt;value&gt;myAdvisor&lt;/value&gt;<br />        &lt;/list&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />  &lt;/beans&gt;</font></p><p>  主程序不需进行任何修改，运行结果已经变样了：</p><p><font face="Courier New" color="#614db3" size="2">  In PrintBeforeAdvice<br />  In FooImpl.printFoo<br />  In FooImpl.dummyFoo</font><br /> <br />  至此，应该已经理解了Spring中AOP的使用方法，当然Spring中AOP最重要的应用是Transaction Manager，举个这方面的applicationContext例子看看：<br /> <br /><font face="Courier New" color="#614db3" size="2">  &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "spring-beans.dtd"&gt;</font></p><p><font face="Courier New" color="#614db3" size="2">  &lt;beans&gt;<br />    &lt;bean id="propertyConfigurer"   <br />         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br />      &lt;property name="location"&gt;<br />        &lt;value&gt;/WEB-INF/jdbc.properties&lt;/value&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />    &lt;bean id="dataSource"<br />          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;<br />      &lt;property name="driverClassName"&gt;<br />        &lt;value&gt;${jdbc.driverClassName}&lt;/value&gt;<br />      &lt;/property&gt;<br />      &lt;property name="url"&gt;<br />        &lt;value&gt;${jdbc.url}&lt;/value&gt;<br />      &lt;/property&gt;<br />      &lt;property name="username"&gt;<br />        &lt;value&gt;${jdbc.username}&lt;/value&gt;<br />      &lt;/property&gt;<br />      &lt;property name="password"&gt;<br />        &lt;value&gt;${jdbc.password}&lt;/value&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />    &lt;bean id="sessionFactory"<br />          class="org.springframework.orm.hibernate.LocalSessionFactoryBean"&gt;<br />      &lt;property name="dataSource"&gt;<br />        &lt;ref local="dataSource"/&gt;<br />      &lt;/property&gt;<br />      &lt;property name="mappingResources"&gt;<br />        &lt;value&gt;smartmenu.hbm.xml&lt;/value&gt;<br />      &lt;/property&gt;<br />      &lt;property name="hibernateProperties"&gt;<br />        &lt;props&gt;<br />          &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;<br />        &lt;/props&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br /> <br />    &lt;bean id="transactionManager"       <br />          class="org.springframework.orm.hibernate.HibernateTransactionManager"&gt;<br />      &lt;property name="sessionFactory"&gt;<br />        &lt;ref local="sessionFactory"/&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />    &lt;bean id="smartmenuTarget" class="SmartMenuHibernate"&gt;<br />      &lt;property name="sessionFactory"&gt;<br />        &lt;ref local="sessionFactory"/&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />    &lt;bean id="smartMenu"<br />        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;<br />      &lt;property name="transactionManager"&gt;<br />        &lt;ref local="transactionManager"/&gt;<br />      &lt;/property&gt;<br />      &lt;property name="target"&gt;<br />        &lt;ref local="smartmenuTarget"/&gt;<br />      &lt;/property&gt;<br />      &lt;property name="transactionAttributes"&gt;<br />        &lt;props&gt;<br />          &lt;prop key="get*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;<br />          &lt;prop key="find*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;<br />        &lt;/props&gt;<br />      &lt;/property&gt;<br />    &lt;/bean&gt;<br />  &lt;/beans&gt;</font><br /> <br />  要想彻底理解Spring的AOP，最好还是多看看源码，开源就是好啊！</p><object class="OBJECT" id="MediaPlayer" style="WIDTH: 300px; HEIGHT: 28px" align="middle" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" twffan="done"></object></div>
										</div>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/zhanglijun33/aggbug/59957.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-25 11:38 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/25/aop.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate+Spring 对DAO的处理实列!</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Tue, 25 Jul 2006 03:23:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/59954.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/59954.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/59954.html</trackback:ping><description><![CDATA[
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td valign="top" align="left" width="100%">
										<div class="diaryTitleBg"> </div>
								</td>
						</tr>
						<tr>
								<td valign="top" align="left" width="100%">
										<div class="diarybody">
												<span class="postbody">引用"Spring"手册上的话说: Hibernate+Spring显然是天生的结合.<br /><br />下面是我用spring处理的一个HibernateDAO实例,可以看到,代码量大大减少了.<br /><br /></span>
												<table cellspacing="1" cellpadding="3" width="90%" align="center" border="0">
														<tbody>
																<tr>
																		<td>
																				<span class="genmed">
																						<b>java代码: </b>
																				</span>
																		</td>
																</tr>
																<tr>
																		<td class="code">
																				<div style="FONT-FAMILY: 'Courier New', Courier, monospace">
																						<br />
																						<br />
																						<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">package</span> infoweb.<span style="COLOR: #000000">dao</span>;<br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> java.<span style="COLOR: #000000">util</span>.<span style="COLOR: #000000">List</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> java.<span style="COLOR: #000000">util</span>.<span style="COLOR: #000000">Iterator</span>;<br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> infoweb.<span style="COLOR: #000000">pojo</span>.<span style="COLOR: #000000">Info</span>;<br /><br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">HibernateException</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">Query</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">Session</span>;<br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> org.<span style="COLOR: #000000">springframework</span>.<span style="COLOR: #000000">orm</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">HibernateCallback</span>;<br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">import</span> org.<span style="COLOR: #000000">springframework</span>.<span style="COLOR: #000000">orm</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">support</span>.<span style="COLOR: #000000">HibernateDaoSupport</span>;<br /><br /><br /><span style="COLOR: #6666ff">/**<br />* &lt;p&gt;Title: &lt;/p&gt;<br />* &lt;p&gt;Description: &lt;/p&gt;<br />* &lt;p&gt;Copyright: Copyright (c) 2004&lt;/p&gt;<br />* &lt;p&gt;Company: &lt;/p&gt;<br />* @author 段洪杰<br />* @version 1.0<br />*/</span><br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span> InfoDAOImpl <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">extends</span> HibernateDaoSupport <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">implements</span> IInfoDAO <span style="COLOR: #000000">{</span><br />  <span style="COLOR: #6666ff">/**<br />   * 构造函数<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> InfoDAOImpl<span style="COLOR: #000000">()</span><span style="COLOR: #000000">{</span><br />    super<span style="COLOR: #000000">()</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 增加记录<br />   * @param info Info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setInfo<span style="COLOR: #000000">(</span>Info info<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">save(</span>info<span style="COLOR: #000000">)</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过ID取得记录<br />   * @param id String<br />   * @return Info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getInfoById<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> id<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    Info info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">load(</span>Info.<span style="COLOR: #000000">class</span>, id<span style="COLOR: #000000">)</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 修改记录<br />   * @param Info info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> modifyInfo<span style="COLOR: #000000">(</span>Info info<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">update(</span>info<span style="COLOR: #000000">)</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 删除记录<br />   * @param Info info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> removeInfo<span style="COLOR: #000000">(</span>Info info<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">delete(</span>info<span style="COLOR: #000000">)</span>;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">/////以下部份不带审核功能                              ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录总数<br />   * @return int<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCount<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info";<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span>queryString<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<br />            <span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取所有记录集合<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfos<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #aaaadd" ?="">List</span> list = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">find(</span>queryString<span style="COLOR: #000000">)</span>;<br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录集合<br />   * @return Iterator<br />   * @param int position, int length<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfos<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info order by info.<span style="COLOR: #000000">id</span> desc";<br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取第一条记录<br />   * @throws Exception<br />   * @return Station<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getFirstInfo<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    Info info = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = "select info from Info as info order by info.<span style="COLOR: #000000">id</span> desc";<br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>iterator.<span style="COLOR: #000000">hasNext())</span><span style="COLOR: #000000">{</span><br />      info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> iterator.<span style="COLOR: #000000">next()</span>;<br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取最后一条记录<br />   * @throws Exception<br />   * @return Station<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getLastInfo<span style="COLOR: #000000">()</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    Info info = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = "select info from Info as info order by info.<span style="COLOR: #000000">id</span> asc";<br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>iterator.<span style="COLOR: #000000">hasNext())</span><span style="COLOR: #000000">{</span><br />      info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> iterator.<span style="COLOR: #000000">next()</span>;<br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪 牳鋈撕推笠禒    ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数, [表中要有 isperson 字段]<br />   * @return int<br />   * @param int isPerson<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByIsperson<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isPerson<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">isperson</span> =" + isPerson;<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span>queryString<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<br />            <span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取所有符合条件记录集合, 模糊查询条件.[表中要有 isperson 字段]<br />   * @return Iterator<br />   * @param int isPerson<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfosByIsperson<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isPerson<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">isperson</span> =" +<br />                         isPerson + " order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #aaaadd" ?="">List</span> list = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">find(</span>queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录集合, 模糊查询条件.[表中要有 isperson 字段]<br />   * @return Iterator<br />   * @param int isPerson,int position, int length<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByIsperson<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isPerson, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">isperson</span> =" +<br />                         isPerson + " order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪  查询部份      ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数, 模糊查询条件.[表中要有 title 字段]<br />   * @return int<br />   * @param String text<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCount<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />        "%'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取所有符合条件记录集合, 模糊查询条件.[表中要有 title 字段]<br />   * @return Iterator<br />   * @param String text<br />   */</span><br /><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfos<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />        "%'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录集合, 模糊查询条件.[表中要有 title 字段]<br />   * @return Iterator<br />   * @param String text,int position, int length<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfos<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> text, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />        "%'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br /><br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪 犠⒉嵯喙貭     ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数.[ 表中要有 registername 字段]<br />   * @return int<br />   * @param String text<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">registername</span> = <span style="COLOR: #0000ff">'" +<br />        registerName + "'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过注册名取得一条记录,如有多条,只取第一条.[表中要有 registername字段]<br />   * @param registername String<br />   * @return Info<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span> Info getInfoByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    Info info = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">registername</span>=<span style="COLOR: #0000ff">'" +<br />        registerName + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>iterator.<span style="COLOR: #000000">hasNext())</span><span style="COLOR: #000000">{</span><br />      info = <span style="COLOR: #000000">(</span>Info<span style="COLOR: #000000">)</span> iterator.<span style="COLOR: #000000">next()</span>;<br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> info;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过注册名取得所有记录集合.[表中要有 registername字段]<br />   * @param registername String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfosByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">registername</span>=<span style="COLOR: #0000ff">'" +<br />        registerName + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过注册名取得记录列表.[表中要有 registername字段]<br />   * @param registername String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByRegisterName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> registerName, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position,<br />                                         <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString =<br />        " select info from Info as info where info.<span style="COLOR: #000000">registername</span>=<span style="COLOR: #0000ff">'" +<br />        registerName + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">///// 以下部份表中要有特定字段才能Õ吩诵袪   犑餍桶婵闋    ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录总数.[ 表中要有 board_id 字段]<br />   * @return int<br />   * @param String boardId<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br /><br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">boardId</span> = <span style="COLOR: #0000ff">'" + boardId +<br />        "'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过版块名取得所有记录集合.[表中要有 board_id字段]<br />   * @param BoardId String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getAllInfosByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" +<br />                         boardId + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过版块名取得记录列表.[表中要有 board_id字段]<br />   * @param BoardId String<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><br />      <span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" +<br />                         boardId + "'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br /><br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取符合条件记录总数.[ 表中要有 board_id 字段,title]  模糊查询title<br />   * @return int<br />   * @param String boardId ,String text<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCountByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId, <span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> count = <span style="COLOR: #000000" ?="">0</span>;<br /><br />    count = <span style="COLOR: #000000">((</span><span style="COLOR: #aaaadd" ?="">Integer</span><span style="COLOR: #000000">)</span> getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">iterate(</span><br />        "select count<span style="COLOR: #000000">(</span>*<span style="COLOR: #000000">)</span> from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" + boardId +<br />        "'</span> and info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text + "%'</span>"<span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">next())</span>.<span style="COLOR: #000000">intValue()</span>;<br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> count;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 通过版块名取得记录列表.[表中要有 board_id字段]  模糊查询title<br />   * @param String boardID,int position, int length<br />   * @return Iterator<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Iterator</span> getInfosByBoard<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> boardId, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> position, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> length,<br />                                  <span style="COLOR: #aaaadd" ?="">String</span> text<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #aaaadd" ?="">Iterator</span> iterator = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>;<br />    <span style="COLOR: #aaaadd" ?="">String</span> queryString = " select info from Info as info where info.<span style="COLOR: #000000">boardId</span>=<span style="COLOR: #0000ff">'" +<br />                         boardId + "'</span> and info.<span style="COLOR: #000000">title</span> like <span style="COLOR: #0000ff">'%" + text +<br />                         "%'</span> order by info.<span style="COLOR: #000000">id</span> desc";<br /><br />    <span style="COLOR: #6666ff">//创建查询</span><br />    Query query = getHibernateTemplate<span style="COLOR: #000000">()</span>.<span style="COLOR: #000000">createQuery(</span>getSession<span style="COLOR: #000000">()</span>, queryString<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的起始点</span><br />    query.<span style="COLOR: #000000">setFirstResult(</span>position<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//设置游标的长度</span><br />    query.<span style="COLOR: #000000">setMaxResults(</span>length<span style="COLOR: #000000">)</span>;<br />    <span style="COLOR: #6666ff">//记录生成</span><br />    <span style="COLOR: #aaaadd" ?="">List</span> list = query.<span style="COLOR: #000000">list()</span>;<br />    <span style="COLOR: #6666ff">//把查询到的结果放入迭代器</span><br />    iterator = list.<span style="COLOR: #000000">iterator()</span>;<br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> iterator;<br /><br />  <span style="COLOR: #000000">}</span><br /><br /><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">/////以下部份带有审核功能                              ///</span><br />  <span style="COLOR: #6666ff">/////                                                ///</span><br />  <span style="COLOR: #6666ff">////////////////////////////////////////////////////////</span><br /><br />  <span style="COLOR: #6666ff">/**<br />   * 取记录总数<br />   * @return int<br />   * @param int isAuditing<br />   */</span><br />  <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> getInfosCount<span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> isAuditing<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span><span style="COLOR: #aaaadd" ?="">Exception</span><span style="COLOR: #000000">{</span><br />    <span style="COLOR: #990066; FON: " border="0" cellspacing="0" cellpadding="0" align="center" 468?=""></span></div>
																		</td>
																</tr>
																<tr>
																		<td>
																				<script src="http://www.blogbus.com/ads/ads.js" type="text/javascript">
																				</script>
																		</td>
																</tr>
														</tbody>
												</table>
										</div>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/zhanglijun33/aggbug/59954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-25 11:23 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/25/goodacticle.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring,hibernate,struts应用中的错误及更正-（3）</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Tue, 11 Jul 2006 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/57650.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/57650.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/57650.html</trackback:ping><description><![CDATA[这两天公司任务不紧，这样就给我不少做试验的机会和时间。今天的试验是在action里面写多个不同的方法，并且要得 到业务层的对象以便进一步处理数据。<br />首先我的action要继承DispatchAction.这样才能实现多个不同的方法放在一个action里。<br />2.在里面写入固定的方法：<br />public void setServlet(ActionServlet actionServlet){<br />   super.setServlet(actionServlet);<br />   ServletContext  servletContext =actionServlet.getServletContext();<br />  WebApplicationContext wac =  WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);<br />//然后就可以得到业务层的对象了。像我昨天说得那样做就行。（注：在这个方法里面可以得到多个不同对象，已经试验通过）<br />然后再一个得到service对象的方法，以供后面的方法使用。<br />3.多个jsp页面可以对应一个action吗？可以，已经试验通过。并且在struts_config.xml里面无须做任何改动。<br />4.myAction?method=addXX后面可以跟其他参数吗？可以，已经试验通过。<br />5，jsp向action发出请求的时候，为什么有时候出现空白异常？这时候你应该从两个方面进行检查<br />  1，检查你的struts_config.xml forwordname<br />   2以上经验是我苦想了一天才得到的。<img src ="http://www.blogjava.net/zhanglijun33/aggbug/57650.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-11 15:10 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/11/STRUTS3.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts,hibernate,spring应用过程中的错误及更正（每日更新）</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Mon, 10 Jul 2006 08:22:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/57522.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/57522.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/57522.html</trackback:ping><description><![CDATA[上接“jsp页面得到业务层的对象”<br />1.我现在想用org.springframework.orm.hibernate.HibernateTransactionManager来给业务对象织入事务管理方法。但在调试的时候却发生了异常:Error registering bean with name 'myTransactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml],系统在给myTransactionManager Bean注册的时候却找不到它的类。的确是很奇怪的问题，HibernateTransactionManager明明就在这儿摆着嘛，怎么系统就是找不到呢。经过几个小时的查找代码档案，发现原来我用的是Hibernate3版本。相应的org.springframework.orm.hibernate.HibernateTransactionManager也应该改成：org.springframework.orm.hibernate3.HibernateTransactionManager.汗！java程序员真累。<br />2.错误2，当我想在页面上得到织入事务管理的service对象时，又有一个错误来了：<br />org.apache.jasper.JasperException: $Proxy2<br />org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)<br />晕吧，代理人的待遇没问题了，可是它就是不给你做代理。经过在jsp页面上的排察：终于找到这一句：<br />   RealnewsService newsservice=(RealnewsService)wac.getBean("newsService");<br />它有什么问题吗？初学者看不出什么错误来，因为语法上一点错也没有，后来经高手指点才如梦初醒：<br />它的声明类型应该是相应的接口。这是spring一贯的风格，（但这至于让我出错吗？郁闷），好。到今天为址，我和关注我的博客的同学应该对spring应用程序的核心配置文件有了一定的理解了。<br />总结一句话：解决问题的方法是：来了问题不要怕，用朴素的理念和执著的态度去战胜bug  ;-)<img src ="http://www.blogjava.net/zhanglijun33/aggbug/57522.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-10 16:22 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/10/zongjie.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring 应用程序配置文件的核心理解</title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/06/spring.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Thu, 06 Jul 2006 03:29:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/06/spring.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/56923.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/06/spring.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/56923.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/56923.html</trackback:ping><description><![CDATA[本文的理解来自实际应用程序。文件名是：applicationContext-hibernate1.xml<br />熟悉spring-hibernate架构的人对它肯定不陌生。它是由支持spring的组件在编程开始自动生成的，但我们不能总是停留在不管不问的状态。否则对程序构造就没有更深一步的理解。<br />如果理清applicationContext-hibernate1.xml的头绪或者手工写它，对于主动改进程序肯定是有益的。<br />我总结出来的顺序是：<br />1.建myDataSource<br />(org.apache.commons.dbcp.BasicDataSource).属性包括DBDriver,URL,UserName,Password.<br />2.mySessionFactory:<br />(org.springframework.orm.hibernate.LocalSessionFactoryBean)属性包括：mappingResources(hbm.xml的集合)，HibernateProperties,myDataSource(注入1).<br />3.myTransactionManager<br />(org.springframework.orm.hibernate.HibernateTransactionManager)mySessionFactory(注入2)<br />以上三步是后面各项配置的基础。从后面开始我们就开始真正的配置我们的Beans了。<br />4.boDAO<br />(com.realnews.yourProject.service.dao.hibernate.boDAOs)注入mySessionFactory.<br />5.boTarget<br />(com.realnews.yourProject.service.spring.boServices) 注入boDAO<br />6.boService<br />（org.springframework.transaction.interceptor.TransactionProxyFactoryBean）注入myTransactionManager及boTarget<br />，并用transactionAttributes设置数据库并发控制级别。例如<br />&lt;property name="transactionAttributes"&gt;<br />   &lt;props&gt;<br />    &lt;prop key="find*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;<br />    &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;<br />   &lt;/props&gt;<br />7.循环第4到第6步即可配置所有需要配置的bean.<br />本文不是摘抄，如果想转摘，请注明出处：<a href="/zhanglijun33">www.blogjava.net/zhanglijun33</a><br />如果想要更详细的资料可以给我留言。<br /><img src ="http://www.blogjava.net/zhanglijun33/aggbug/56923.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-06 11:29 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/06/spring.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring Framework之最佳实践二  </title><link>http://www.blogjava.net/zhanglijun33/archive/2006/07/05/lijun.html</link><dc:creator>智者无疆</dc:creator><author>智者无疆</author><pubDate>Wed, 05 Jul 2006 08:38:00 GMT</pubDate><guid>http://www.blogjava.net/zhanglijun33/archive/2006/07/05/lijun.html</guid><wfw:comment>http://www.blogjava.net/zhanglijun33/comments/56805.html</wfw:comment><comments>http://www.blogjava.net/zhanglijun33/archive/2006/07/05/lijun.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/zhanglijun33/comments/commentRss/56805.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhanglijun33/services/trackbacks/56805.html</trackback:ping><description><![CDATA[
		<div class="posttitle">
				<table cellspacing="6" cellpadding="0" width="96%" border="0">
						<tbody>
								<tr>
										<td valign="top" height="275">
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">Spring Framework最得以出名的是与Hibernate的无缝链接，基本上用Spring，就会用Hibernate。可惜的是Spring提供的HibernateTemplate功能显得不够，使用起来也不是很方便。我们编程序时，一般先写BusinessService，由BusinessService调DAO来执行存储，在这方面Spring没有很好的例子，造成真正想用好它，并不容易。</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">我们的思路是先写一个BaseDao，仿照HibernateTemplate，将基本功能全部实现：</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">public class BaseDao extends HibernateDaoSupport{</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    private Log log = LogFactory.getLog(getClass());</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Session openSession() {<br />        return SessionFactoryUtils.getSession(getSessionFactory(), false);<br />    }</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object get(Class entityClass, Serializable id) throws DataAccessException {<br />        Session session = openSession();<br />        try {<br />            return session.get(entityClass, id);<br />        }<br />        catch (HibernateException ex) {<br />            throw SessionFactoryUtils.convertHibernateAccessException(ex);<br />        }<br />    }</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Serializable create(Object entity) throws DataAccessException {<br />        Session session = openSession();<br />        try {<br />            return session.save(entity);<br />        }<br />        catch (HibernateException ex) {<br />            throw SessionFactoryUtils.convertHibernateAccessException(ex);<br />        }<br />    }</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">...</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">其它的DAO，从BaseDao继承出来，这样写其他的DAO，代码就会很少。</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">从BaseDao继承出来EntityDao，专门负责一般实体的基本操作，会更方便。</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">public interface EntityDao {</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object get(Class entityClass, Serializable id) throws DataAccessException;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object load(Class entityClass, Serializable id) throws DataAccessException;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Serializable create(Object entity) throws DataAccessException;<br />...}</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">/**<br /> * Base class for Hibernate DAOs.  This class defines common CRUD methods for<br /> * child classes to inherit. User Sping AOP Inteceptor<br /> */<br />public class EntityDaoImpl extends BaseDao implements EntityDao{</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">}</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">为了Transaction的控制，采用AOP的方式：</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">public interface EntityManager {</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object get(Class entityClass, Serializable id);</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object load(Class entityClass, Serializable id);</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Serializable create(Object entity);<br />...</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">}</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">/**<br /> * Base class for Entity Service. User Sping AOP Inteceptor<br /> */<br />public class EntityManagerImpl implements EntityManager {</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    private EntityDao entityDao;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public void setEntityDao(EntityDao entityDao) {<br />        this.entityDao = entityDao;<br />    }</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object get(Class entityClass, Serializable id) {<br />        return entityDao.get(entityClass, id);<br />    }</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">    public Object load(Class entityClass, Serializable id) {<br />        return entityDao.load(entityClass, id);<br />    }<br />...</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">}</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">这样我们就有了一个通用的Hibernate实体引擎，可以对任何Hibernate实体实现基本的增加、修改、删除、查询等。</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">其它的BusinessService就可以继承EntityManager，快速实现业务逻辑。</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">具体XML配置如下：</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff"> &lt;!-- Oracle JNDI DataSource for J2EE environments --&gt;<br /> &lt;bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;<br />  &lt;property name="jndiName"&gt;&lt;value&gt;java:comp/env/jdbc/testPool&lt;/value&gt;&lt;/property&gt;<br /> &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff"> &lt;!-- Hibernate SessionFactory for Oracle --&gt;<br /> &lt;!-- Choose the dialect that matches your "dataSource" definition --&gt;<br /> &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"&gt;<br />  &lt;property name="dataSource"&gt;&lt;ref local="dataSource"/&gt;&lt;/property&gt;<br />  &lt;property name="mappingResources"&gt;<br />   &lt;value&gt;user-hbm.xml&lt;/value&gt;<br />  &lt;/property&gt;<br />  &lt;property name="hibernateProperties"&gt;<br />   &lt;props&gt;<br />    &lt;prop key="hibernate.dialect"&gt;net.sf.hibernate.dialect.OracleDialect&lt;/prop&gt;<br />    &lt;prop key="hibernate.cache.provider_class"&gt;net.sf.ehcache.hibernate.Provider&lt;/prop&gt;<br />    &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;<br />                  &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;<br />   &lt;/props&gt;<br />  &lt;/property&gt;<br /> &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff"> &lt;!-- AOP DAO Intecepter --&gt;<br />        &lt;bean id="hibernateInterceptor" class="org.springframework.orm.hibernate.HibernateInterceptor"&gt;<br />          &lt;property name="sessionFactory"&gt;<br />            &lt;ref bean="sessionFactory"/&gt;<br />          &lt;/property&gt;<br />        &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">        &lt;bean id="entityDaoTarget" class="com.gpower.services.entity.dao.EntityDaoImpl"&gt;<br />          &lt;property name="sessionFactory"&gt;<br />            &lt;ref bean="sessionFactory"/&gt;<br />          &lt;/property&gt;<br />        &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">        &lt;bean id="entityDao" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;<br />          &lt;property name="proxyInterfaces"&gt;<br />            &lt;value&gt;com.gpower.services.entity.dao.EntityDao&lt;/value&gt;<br />          &lt;/property&gt;<br />          &lt;property name="interceptorNames"&gt;<br />            &lt;list&gt;<br />              &lt;value&gt;hibernateInterceptor&lt;/value&gt;<br />              &lt;value&gt;entityDaoTarget&lt;/value&gt;<br />            &lt;/list&gt;<br />          &lt;/property&gt;<br />        &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff"> &lt;!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --&gt;<br /> &lt;bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"&gt;<br />  &lt;property name="sessionFactory"&gt;&lt;ref local="sessionFactory"/&gt;&lt;/property&gt;<br /> &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff"> &lt;!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) --&gt;<br /> &lt;!--<br /> &lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/&gt;<br /> --&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff"> &lt;!-- Transactional proxy for the Application primary business object --&gt;<br />        &lt;bean id="entityManagerTarget" class="com.gpower.services.entity.EntityManagerImpl"&gt;<br />          &lt;property name="entityDao"&gt;<br />            &lt;ref bean="entityDao"/&gt;<br />          &lt;/property&gt;<br />        &lt;/bean&gt;</font>
												</p>
												<p>
														<font style="BACKGROUND-COLOR: #ffffff">        &lt;bean id="entityManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;<br />          &lt;property name="transactionManager"&gt;<br />            &lt;ref bean="transactionManager"/&gt;<br />          &lt;/property&gt;<br />          &lt;property name="target"&gt;<br />            &lt;ref bean="entityManagerTarget"/&gt;<br />          &lt;/property&gt;<br />          &lt;property name="transactionAttributes"&gt;<br />     &lt;props&gt;<br />       &lt;prop key="get*"&gt;PROPAGATION_SUPPORTS&lt;/prop&gt;<br />       &lt;prop key="*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;<br />     &lt;/props&gt;<br />          &lt;/property&gt;<br />        &lt;/bean&gt;<br /></font>
												</p>
												<br />
										</td>
								</tr>
						</tbody>
				</table>
				<a class="singleposttitle" id="viewpost1_TitleUrl" href="/zhanglijun33/articles/zhanglijun3.html">
						<font color="#333333">Spring Framework之最佳实践二</font>
				</a>
		</div>
		<table height="24" cellspacing="4" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td class="boldredfont" width="91%">
										<font style="BACKGROUND-COLOR: #ffffff">
										</font>
								</td>
						</tr>
				</tbody>
		</table>
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td background="/images/cgal_23.gif" height="7">
										<font style="BACKGROUND-COLOR: #ffffff">
												<img height="7" src="http://www.gpowersoft.com/images/spacer.gif" width="1" />
										</font>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/zhanglijun33/aggbug/56805.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhanglijun33/" target="_blank">智者无疆</a> 2006-07-05 16:38 <a href="http://www.blogjava.net/zhanglijun33/archive/2006/07/05/lijun.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>