﻿<?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-Skynet</title><link>http://www.blogjava.net/Good-Game/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 18 May 2008 00:36:27 GMT</lastBuildDate><pubDate>Sun, 18 May 2008 00:36:27 GMT</pubDate><ttl>60</ttl><item><title>spring 与 hibernate 整合(事务)</title><link>http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 09 May 2008 05:47:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/199477.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/199477.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/199477.html</trackback:ping><description><![CDATA[参考：第 9 章 事务管理 - Spring Framework  reference 2.0.5  参考手册中文版<br /><font color="#0000ff">http://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch09.html</font><br /><br />先从配置文件开始：<br />源码：<a href="/Files/Good-Game/springAop.rar">springAop.rar</a><br /><br />需要jar<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="src"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="java"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="con"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="org.eclipse.jdt.launching.JRE_CONTAINER"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/aspectjrt.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/aspectjweaver.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/spring.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/spring-sources.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/commons-logging-1.0.4.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/cglib-nodep-2.1_3.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/hibernate3.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/log4j-1.2.11.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="con"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/dom4j-1.6.1.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/commons-collections-2.1.1.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/mysql.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/jta.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/antlr-2.7.6.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="output"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="bin"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br /><font color="#a52a2a">spring 配置<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans </span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/beans"</span><span style="color: rgb(255, 0, 0);"><br />       xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0);"><br />       xmlns:aop</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/aop"</span><span style="color: rgb(255, 0, 0);"><br />       xmlns:tx</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/tx"</span><span style="color: rgb(255, 0, 0);"><br />       xsi:schemaLocation</span><span style="color: rgb(0, 0, 255);">="<br />       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd<br />       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd<br />       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />       <br />  <br />  </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> daoCalss : extends HibernateDaoSupport implements BeanDao </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="beanDao"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="dao.imp.BeanDaoImp"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">ref</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  <br />   <br />   </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> hibernate3 sessionFactory </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);">     <br />        class</span><span style="color: rgb(0, 0, 255);">="org.springframework.orm.hibernate3.LocalSessionFactoryBean"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br />        </span><font><font color="#a52a2a"><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> spring 与 hibernate 联系 </span><span style="color: rgb(0, 128, 0);">--&gt;</span></font></font><span style="color: rgb(0, 0, 0);">   <br />       </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="configLocation"</span><span style="color: rgb(255, 0, 0);"> value</span><span style="color: rgb(0, 0, 255);">="classpath:hibernate.cfg.xml"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">  <br />   </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  <br />   <br />   </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> aop 与事务联系 aopBean&lt;-&gt;txAdvice  </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />           </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 逻辑拦截 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />         </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:pointcut </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="aopBean"</span><span style="color: rgb(255, 0, 0);"> expression</span><span style="color: rgb(0, 0, 255);">="execution(* *.*.*(..))"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:advisor </span><span style="color: rgb(255, 0, 0);">advice-ref</span><span style="color: rgb(0, 0, 255);">="txAdvice"</span><span style="color: rgb(255, 0, 0);"> pointcut-ref</span><span style="color: rgb(0, 0, 255);">="aopBean"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 事务适配器 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />       </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="txManager"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="org.springframework.orm.hibernate3.HibernateTransactionManager"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);"> ref</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 事务原子 具体方法进行什么事务 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:advice </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="txAdvice"</span><span style="color: rgb(255, 0, 0);"> transaction-manager</span><span style="color: rgb(0, 0, 255);">="txManager"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:attributes</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:method </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="get*"</span><span style="color: rgb(255, 0, 0);"> read-only</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:method </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">tx:attributes</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">tx:advice</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /></font><br /><font color="#a52a2a"><b>hibernate 配置</b></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE hibernate-configuration PUBLIC<br />        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"<br />        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">hibernate-configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">session-factory </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="asdf"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="hibernate.dialect"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">mysql</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="myeclipse.connection.profile"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        com.mysql.jdbc.Driver<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.url"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        jdbc:mysql://localhost/aop<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="show_sql"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">true</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.username"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">root</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.password"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.driver_class"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        com.mysql.jdbc.Driver<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="dialect"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        org.hibernate.dialect.MySQLDialect<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">mapping </span><span style="color: rgb(255, 0, 0);">resource</span><span style="color: rgb(0, 0, 255);">="bean/UnitBean.hbm.xml"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">session-factory</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">hibernate-configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br />dao 类（接口）<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> dao.imp;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.List;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.orm.hibernate3.support.HibernateDaoSupport;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> bean.UnitBean;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> dao.BeanDao;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> BeanDaoImp </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> HibernateDaoSupport </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> BeanDao{<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> addBean(UnitBean unitBean) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getHibernateTemplate().save(unitBean);<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> List</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">UnitBean</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> getBeanByAll() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getHibernateTemplate().find(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> from </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">UnitBean.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">.getName());<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> removeBean(</span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> beanId) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getHibernateTemplate().delete(<br />                getHibernateTemplate().get(UnitBean.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">, beanId)<br />            );<br />    }<br />    <br />}<br /></span></div><br />Main 类<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> unit;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.ApplicationContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.support.ClassPathXmlApplicationContext;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> dao.BeanDao;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> bean.UnitBean;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Main {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br />           ApplicationContext ctx </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ClassPathXmlApplicationContext(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           BeanDao dao </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (BeanDao) ctx.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">beanDao</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           UnitBean bean </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> UnitBean();<br />           bean.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">xx</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           bean.setPass(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           dao.addBean(bean);<br />           <br />           </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(UnitBean unitBean : dao.getBeanByAll() ){<br />               System.out.println( unitBean.getId() );<br />           }<br />           <br />           dao.removeBean(bean.getId());<br />           <br />    }<br />}<br /></span></div>结果：<br /><font color="#006400">Hibernate: insert into bean (name, pass) values (?, ?)<br />Hibernate: select unitbean0_.id as id0_, unitbean0_.name as name0_, unitbean0_.pass as pass0_ from bean unitbean0_<br />1<br />Hibernate: select unitbean0_.id as id0_0_, unitbean0_.name as name0_0_, unitbean0_.pass as pass0_0_ from bean unitbean0_ where unitbean0_.id=?<br />Hibernate: delete from bean where id=?<br /></font><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/199477.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-05-09 13:47 <a href="http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring AspectJ 基本使用</title><link>http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Thu, 08 May 2008 02:08:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/199146.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/199146.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/199146.html</trackback:ping><description><![CDATA[我的aop 基础<br /><ul><li><a id="Singlecolumn2_Categories_CatList_ctl00_LinkList_ctl02_RssLink" title="Subscribe to AOP(3)" href="/Good-Game/category/26564.html/rss"><img title="Subscribe to AOP(3)" src="/Skins/KJC/Images/xmlsmall.gif" style="border-width: 0px;" /></a><a id="Singlecolumn2_Categories_CatList_ctl00_LinkList_ctl02_Link" href="/Good-Game/category/26564.html">AOP(3)</a></li></ul>spring 实际使用 （这就使用一个例子说明）<br /><span style="color: rgb(0, 0, 255);"><br />
测试类以及结果：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> unit;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.ApplicationContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.support.ClassPathXmlApplicationContext;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> bean.HelloService;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Main {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br />           ApplicationContext context </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ClassPathXmlApplicationContext(      <br />                   </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);    <br />           HelloService service </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (HelloService) context.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">helloService</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);    <br />           service.annotationAop();<br />           <br />           System.out.println();<br />           <br />           service.xmlAop();<br />           <br />    }<br />}<br /><font color="#a52a2a"><b>结果：</b></font><br /><font color="#0000ff"> annotationAop</font><font color="#006400">//正常方法运行</font><br /><font color="#0000ff">aop--AspectJ! </font><font color="#008000">//</font></span><font color="#008000"><span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 0);">annotation</span></span></font><span style="color: rgb(0, 0, 0);"><font color="#008000">拦截 </font><br /><br /><font color="#0000ff"> xmlAop</font>  </span><span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 0);">/<font color="#006400">/正常方法运行</font></span></span><br /><span style="color: rgb(0, 0, 0);"> <font color="#0000ff">aop--XmlAop! </font></span><span style="color: rgb(0, 0, 255);"><font color="#006400"><span style="color: rgb(0, 0, 0);">//</span><span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 0);">配置</span></span></font><span style="color: rgb(0, 0, 0);"><font color="#006400">拦截</font></span></span></div><br /></span><br /><br /><b><font color="#00ee00"><font color="#008000"> use jar</font></font></b><ul><li><font color="#0000ff">--aspectjrt.jar</font></li><li><font color="#0000ff">--aspectjweaver.jar</font></li><li><font color="#0000ff">--acglib-nodep-2.1_3.jar</font></li><li><font color="#0000ff">--commons-logging.jar</font></li><li><font color="#0000ff">--spring.jar</font></li><li><font color="#0000ff">--spring-aspects.jar</font></li></ul><font color="#008000"><b>XML配置</b></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans </span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/beans"</span><span style="color: rgb(255, 0, 0);">       <br />            xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0);"><br />            xmlns:aop</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/aop"</span><span style="color: rgb(255, 0, 0);"><br />               xsi:schemaLocation</span><span style="color: rgb(0, 0, 255);">=        <br />                   "http://www.springframework.org/schema/beans         <br />                   http://www.springframework.org/schema/beans/spring-beans.xsd         <br />                   http://www.springframework.org/schema/aop         <br />                   http://www.springframework.org/schema/aop/spring-aop.xsd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        <br />        </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 测试使用类 分别由 方法 annotationAop/xmlAop </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="helloService"</span><span style="color: rgb(255, 0, 0);">       <br />            class</span><span style="color: rgb(0, 0, 255);">="bean.HelloService"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">    <br />        <br />            <br />        </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> annotation aop 拦截 使用@Aspect <br />            @Pointcut("execution(* annotationAop(..))")  <br />            @AfterReturning("mainMethod()")  <br />        </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="xmlAop"</span><span style="color: rgb(255, 0, 0);"> <br />            class</span><span style="color: rgb(0, 0, 255);">="aop.AnnotationAspectJ"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:aspectj-autoproxy</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">    <br />        <br />        <br />        </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> xml aop  配置文件拦截 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="XmlAspectJ"</span><span style="color: rgb(255, 0, 0);">       <br />            class</span><span style="color: rgb(0, 0, 255);">="aop.XmlAspectJ"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">     <br />             </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:aspect </span><span style="color: rgb(255, 0, 0);">ref</span><span style="color: rgb(0, 0, 255);">="XmlAspectJ"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                 </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:pointcut </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="mainMethod"</span><span style="color: rgb(255, 0, 0);"> expression</span><span style="color: rgb(0, 0, 255);">="execution(* xmlAop(..))"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">    <br />                 </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:after-returning </span><span style="color: rgb(255, 0, 0);">pointcut-ref</span><span style="color: rgb(0, 0, 255);">="mainMethod"</span><span style="color: rgb(255, 0, 0);"> method</span><span style="color: rgb(0, 0, 255);">="goXmlAop"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">     <br />             </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">aop:aspect</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br />         </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">    <br />            <br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /><span style="color: rgb(0, 0, 255);">HelloService.java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> bean;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HelloService {  <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> annotationAop() {    <br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> annotationAop </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> xmlAop(){<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> xmlAop </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br /></span><span style="color: rgb(0, 0, 255);">AnnotationAspectJ.java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> aop;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.aspectj.lang.annotation.AfterReturning;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.aspectj.lang.annotation.Aspect;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.aspectj.lang.annotation.Pointcut;<br /><br />@Aspect<br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> AnnotationAspectJ {  <br />    @Pointcut(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">execution(* annotationAop(..))</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)  <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> mainMethod() {}  <br />    <br />    @AfterReturning(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">mainMethod()</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)  <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> sayHello() {    <br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">aop--AspectJ!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />    }<br />}<br /></span></div><br /></span><span style="color: rgb(0, 0, 255);">XmlAspectJ.java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> aop;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> XmlAspectJ {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> goXmlAop(){<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> aop--XmlAop! </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br /><br /></span><span style="color: rgb(0, 0, 255);"><br /></span><span style="color: rgb(0, 0, 255);"><br /></span><br /><br /><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/199146.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-05-08 10:08 <a href="http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java regex 正则部分高级特性使用</title><link>http://www.blogjava.net/Good-Game/archive/2008/05/04/197990.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Sun, 04 May 2008 01:59:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/05/04/197990.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/197990.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/05/04/197990.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/197990.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/197990.html</trackback:ping><description><![CDATA[这就不介绍了 代码上：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> unit;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.regex.Matcher;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.regex.Pattern;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.junit.Assert;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.junit.Test;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> RegexUnit {<br /><br /><br />    @Test<br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * &lt;p&gt;向前\向后查找&lt;/p&gt;<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> unit9()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        String testStr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">http://www.google.com</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />        <br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> 一般查找<br />         * .+(:) 查询出结果包含 :<br />         </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        Pattern pattern </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Pattern.compile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.+(:)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);        <br />        Matcher matcher </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  pattern.matcher(testStr);<br />            Assert.assertTrue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">错误： 查找出结果通过 .+(:) 此regex没有包含 : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                    matcher.find() </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> matcher.group().equals(</span><span style="color: rgb(0, 0, 0);">"</span><b><font color="#0000ff"><span style="color: rgb(0, 0, 0);">http:</span></font></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />        <br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">  向前查找<br />         *  .+(?=:) 查询结果不包含 :<br />         </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        Pattern pattern2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Pattern.compile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.+(?=:)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Matcher matcher2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pattern2.matcher(testStr);<br />            Assert.assertTrue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">错误： 查找出结果通过 .+(?=:) 此regex有包含 : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                    matcher2.find()</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> matcher2.group().equals(</span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">http</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> 向后查找<br />         * (?&lt;=:).+<br />         </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        Pattern pattern3 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Pattern.compile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">(?&lt;=://).+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Matcher matcher3 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pattern3.matcher(testStr);<br />            Assert.assertTrue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">错误：查找出结果包含 http:// 不向后查询</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                    matcher3.find()</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> matcher3.group().equals(</span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">www.google.com</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />    }<br /><br /><br />    @Test<br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> 回朔应用 <br />     *  查询回朔、回朔替换、回朔大小写替换<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> unit8()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        String testStr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">this is a block of of test,</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"><br />                            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> <b>several words here are are </b></span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"><br />                            </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> <b>repeated , and and they should not be.</b> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />        <br />        Pattern pattern </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Pattern.compile(</span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">[ ]+(\\w+)[ ]+\\1</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Matcher matcher </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pattern.matcher(testStr);<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">查询结果 <b>are are </b></span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        Assert.assertTrue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">错误：regex 不匹配 </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, <br />                matcher.find()</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">matcher.group().split(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).length</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);"> );<br />        <br />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">( matcher.find() ){<br />            Assert.assertTrue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">错误：regex 不匹配 </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, <br />                    matcher.group().split(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).length</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);"> );<br />        }<br />        <br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">替换</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        String testStr2s </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">313-555-1234</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />        Pattern pattern2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Pattern.compile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">(\\d{3})(-)(\\d{3})(-)(\\d{4})</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Matcher mtmp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  pattern2.matcher(testStr2s);<br />        Assert.assertTrue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">错误：没有查替换</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                mtmp.find() </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> <br />                    mtmp.replaceAll(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">($1) $3-$5</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).equals(</span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">(313) 555-1234</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) );<br />        <br />        <br />        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">大小写替换(java 不能成功)<br />         *  \E 结束 \L 或 \U转换<br />         *  \l  \L 把下一个字符(串)换为小写<br />         *  \ u  \U 把下一个字符(串)转换为大写 <br />         </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />        String testStr3 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><b><span style="color: rgb(0, 0, 0);">tt:google:xx</span></b><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />        Pattern pattern3 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Pattern.compile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">(?&lt;=:)(.+)(?=:)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        Matcher matcher2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pattern3.matcher(testStr3);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( matcher2.find())<br />            System.out.println( matcher2.group() ) ;<br />    }<br />    <br />    <br />}<br /></span></div><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/197990.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-05-04 09:59 <a href="http://www.blogjava.net/Good-Game/archive/2008/05/04/197990.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql 权限控制笔记</title><link>http://www.blogjava.net/Good-Game/archive/2008/04/29/197206.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 29 Apr 2008 05:52:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/04/29/197206.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/197206.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/04/29/197206.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/197206.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/197206.html</trackback:ping><description><![CDATA[
		<p>
				<font color="#006400">
						<strong>
								<span>
			MySQL</span>
						</strong>存取控制包含<span>2</span>个阶段：</font>
		</p>
		<ul type="disc">
				<li>阶段<span>1</span>：服务器检查是否允许你连接。</li>
				<li>阶段<span>2</span>：假定你能连接，服务器检查你发出的每个请求。看你是否有足够的权限实施它。例如，如果你从数据库表中选择<span>(select)</span>行或从数据库删除表，服务器确定你对表有<span>SELECT</span>权限或对数据库有<span>DROP</span>权限。</li>
		</ul>
		<span class="section">
		</span>
		<a href="http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#user-account-management">参考 ：
		5.8. MySQL用户账户管理</a>
		<br />
		<br />1.权限查看<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> show grants </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">root</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">localhost</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">-------------------------------------------------------------------+</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"> Grants </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> root</span><span style="color: rgb(0, 128, 0);">@localhost</span><span style="color: rgb(0, 0, 0);">                                           </span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">-------------------------------------------------------------------+</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">ALL</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">PRIVILEGES</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">root</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">localhost</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">WITH</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">OPTION</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">-------------------------------------------------------------------+</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"> row </span><span style="color: rgb(128, 128, 128);">in</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(128, 0, 0); font-weight: bold;">0.06</span><span style="color: rgb(0, 0, 0);"> sec)</span></div><br />2.权限设置<br /><span class="section"></span><a href="http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#adding-users">
			5.8.2. 向MySQL增加新用户账户</a><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">ALL</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">PRIVILEGES</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">monty</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">localhost</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     IDENTIFIED </span><span style="color: rgb(0, 0, 255);">BY</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">some_pass</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">WITH</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">OPTION</span><span style="color: rgb(0, 0, 0);">;<br /></span><font color="#006400"><span><span></span></span></font><span style="color: rgb(0, 0, 0);"><br />mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">ALL</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">PRIVILEGES</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">monty</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">%</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     IDENTIFIED </span><span style="color: rgb(0, 0, 255);">BY</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">some_pass</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">WITH</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">OPTION</span><span style="color: rgb(0, 0, 0);">;</span><font color="#006400"></font><br /><font color="#006400"><span><span>  
			</span></span>其中两个账户有相同的用户名<span>monty</span>和密码<span>some_pass</span>。两个账户均为超级用户账户，具有完全的权限可以做任何事情。一个账户<span> 
			(</span><span>'monty'@'localhost'</span><span>)</span>只用于从本机连接时。另一个账户<span>(</span><span>'monty'@'%'</span><span>)</span>可用于从其它主机连接。</font><br /><span style="color: rgb(0, 0, 0);"><br /></span><br /><span style="color: rgb(0, 0, 0);">mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> RELOAD,PROCESS </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">admin</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">localhost</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /></span><font color="#006400">该账户只用于从本机连接。授予了<span>RELOAD</span>和<span>PROCESS</span>管理权限。这些权限允许<span>admin</span>用户执行<strong><span>mysqladmin 
			reload</span></strong>、<strong><span>mysqladmin 
			refresh</span></strong>和<strong><span>mysqladmin 
			flush-</span></strong><span><b><i><span>xxx</span></i></b></span>命令，以及<strong><span>mysqladmin 
			processlist</span></strong>。未授予访问数据库的权限。你可以通过<span>GRANT</span>语句添加此类权限。</font><br /><span style="color: rgb(0, 0, 0);"><br />mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> USAGE </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">dummy</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">localhost</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /></span><font color="#006400"><span><span>   
			</span></span>一个账户有用户名<span>dummy</span>，没有密码。该账户只用于从本机连接。未授予权限。通过<span>GRANT</span>语句中的<span>USAGE</span>权限，你可以创建账户而不授予任何权限。它可以将所有全局权限设为<span>'N'</span>。假定你将在以后将具体权限授予该账户。</font><br /></div><br />下面的例子创建<span>3</span>个账户，允许它们访问专用数据库。每个账户的用户名为<span>custom</span>，密码为<span><span>obscure</span>。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 0, 0);"><br />mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">INSERT</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">UPDATE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">DELETE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">DROP</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> bankaccount.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">custom</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">localhost</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     IDENTIFIED </span><span style="color: rgb(0, 0, 255);">BY</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">obscure</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /><br />mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">INSERT</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">UPDATE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">DELETE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">DROP</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> expenses.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">custom</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">whitehouse.gov</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     IDENTIFIED </span><span style="color: rgb(0, 0, 255);">BY</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">obscure</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /><br />mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">GRANT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">INSERT</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">UPDATE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">DELETE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 255);">DROP</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">ON</span><span style="color: rgb(0, 0, 0);"> customer.</span><span style="color: rgb(128, 128, 128);">*</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 255);">TO</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">custom</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">@</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">server.domain</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(128, 128, 128);">-&gt;</span><span style="color: rgb(0, 0, 0);">     IDENTIFIED </span><span style="color: rgb(0, 0, 255);">BY</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">obscure</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br /><font color="#006400"><br />这3个账户可以用于：<br /><br />·         第1个账户可以访问bankaccount数据库，但只能从本机访问。<br /><br />·         第2个账户可以访问expenses数据库，但只能从主机whitehouse.gov访问。<br /><br />·         第3个账户可以访问customer数据库，但只能从主机server.domain访问。<br /><br />要想不用GRANT设置custom账户，使用INSERT语句直接修改 授权表：</font></span></div><br /></span><h3 class="title">
			5.8.3. 从MySQL删除用户账户<span></span></h3><h3 class="title"><span>DROP USER <span><i>user</i></span>;</span></h3><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/197206.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-04-29 13:52 <a href="http://www.blogjava.net/Good-Game/archive/2008/04/29/197206.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql 游标使用</title><link>http://www.blogjava.net/Good-Game/archive/2008/04/27/196486.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Sun, 27 Apr 2008 09:05:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/04/27/196486.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/196486.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/04/27/196486.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/196486.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/196486.html</trackback:ping><description><![CDATA[请使用 mysql 1.5 或以上version;<br />测试表 level ;<br />create table <span style="color: rgb(0, 0, 0);">test.</span>level (name varchar(20));<br />再 insert 些数据 ;<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">初始化</span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"> <br /> </span><span style="color: rgb(0, 0, 255);">drop</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">procedure</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">exists</span><span style="color: rgb(0, 0, 0);">  useCursor </span><span style="color: rgb(128, 128, 128);">//</span><span style="color: rgb(0, 0, 0);">    <br /> <br /> </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">建立 存储过程 create </span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"> <br /> </span><span style="color: rgb(0, 0, 255);">CREATE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">PROCEDURE</span><span style="color: rgb(0, 0, 0);"> useCursor()<br />    </span><span style="color: rgb(0, 0, 255);">BEGIN</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">局部变量的定义 declare</span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"> <br />         </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> tmpName </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">20</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"> ;<br />         </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> allName </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">255</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(0, 0, 0);"> ;<br />         <br />         </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> cur1 </span><span style="color: rgb(0, 0, 255);">CURSOR</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">FOR</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> name </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> test.</span><b><span style="color: rgb(0, 0, 255);">level</span></b><span style="color: rgb(0, 0, 0);"> ;<br />         <br />         </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">    mysql 不知道为什么用异常加入判断 ？<br />          *    此请参考官方文档 </span><span class="section"><span></span></span><a href="http://dev.mysql.com/doc/refman/5.1/zh/stored-procedures.html#cursors">20.2.11.   
光标</a><span style="color: rgb(0, 128, 128);"> 光标 <br />          *        这把 游标 异常后 捕捉 <br />          *        并设置 循环使用 变量 tmpname 为 null 跳出循环。<br />          </span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"><br />         </span><span style="color: rgb(0, 0, 255);">declare</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">CONTINUE</span><span style="color: rgb(0, 0, 0);"> HANDLER </span><span style="color: rgb(0, 0, 255);">FOR</span><span style="color: rgb(0, 0, 0);"> SQLSTATE </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">02000</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">SET</span><span style="color: rgb(0, 0, 0);"> tmpname </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />    <br />    <br />    </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">开游标</span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"> <br />     </span><span style="color: rgb(0, 0, 255);">OPEN</span><span style="color: rgb(0, 0, 0);"> cur1;<br />         </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">游标向下走一步</span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"> <br />         </span><span style="color: rgb(0, 0, 255);">FETCH</span><span style="color: rgb(0, 0, 0);"> cur1 </span><span style="color: rgb(0, 0, 255);">INTO</span><span style="color: rgb(0, 0, 0);"> tmpName;<br />         <br />         </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);"> 循环体 这很明显 把游标查询出的 name 都加起并用 ; 号隔开 </span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">WHILE</span><span style="color: rgb(0, 0, 0);"> ( tmpname </span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">not</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) DO<br />          </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> tmpName </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> CONCAT(tmpName ,";") ;<br />          </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> allName </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> CONCAT(allName ,tmpName) ;<br />        </span><span style="color: rgb(0, 128, 128);">/*</span><span style="color: rgb(0, 128, 128);">游标向下走一步</span><span style="color: rgb(0, 128, 128);">*/</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">FETCH</span><span style="color: rgb(0, 0, 0);"> cur1 </span><span style="color: rgb(0, 0, 255);">INTO</span><span style="color: rgb(0, 0, 0);"> tmpName;<br />      </span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">WHILE</span><span style="color: rgb(0, 0, 0);">;<br />  <br />    </span><span style="color: rgb(0, 0, 255);">CLOSE</span><span style="color: rgb(0, 0, 0);"> cur1;<br />    <br />    </span><span style="color: rgb(0, 0, 255);">select</span><span style="color: rgb(0, 0, 0);"> allName ;<br /></span><span style="color: rgb(0, 0, 255);">END</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(128, 128, 128);">//</span><span style="color: rgb(0, 0, 0);"><br />call useCursor()</span><span style="color: rgb(128, 128, 128);">//</span><span style="color: rgb(0, 0, 0);"><br /> </span></div><br />运行结果：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">mysql</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(0, 0, 0);"> call useCursor()</span><span style="color: rgb(128, 128, 128);">//</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">------------------------------------+</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"> allName                              </span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">------------------------------------+</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"> f1;c3;c6;c5;c2;c4;c1;f1;f3;f4;f2;f5; </span><span style="color: rgb(128, 128, 128);">|</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(128, 128, 128);">+</span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">------------------------------------+</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"> row </span><span style="color: rgb(128, 128, 128);">in</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(128, 0, 0); font-weight: bold;">0.00</span><span style="color: rgb(0, 0, 0);"> sec)</span></div><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/196486.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-04-27 17:05 <a href="http://www.blogjava.net/Good-Game/archive/2008/04/27/196486.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate 数据结构（ 树、多对多 结构表示 ）</title><link>http://www.blogjava.net/Good-Game/archive/2008/04/26/196293.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Sat, 26 Apr 2008 10:30:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/04/26/196293.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/196293.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/04/26/196293.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/196293.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/196293.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: level 类：Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->package hbm;import java.util.Set;/** * @hibernate.class table = "level" * where = " visible = ...&nbsp;&nbsp;<a href='http://www.blogjava.net/Good-Game/archive/2008/04/26/196293.html'>阅读全文</a><img src ="http://www.blogjava.net/Good-Game/aggbug/196293.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-04-26 18:30 <a href="http://www.blogjava.net/Good-Game/archive/2008/04/26/196293.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ant hbm 使用</title><link>http://www.blogjava.net/Good-Game/archive/2008/04/25/195920.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 25 Apr 2008 03:31:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/04/25/195920.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/195920.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/04/25/195920.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/195920.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/195920.html</trackback:ping><description><![CDATA[你可以参考：<a id="viewpost1_TitleUrl" class="singleposttitle" href="../archive/2008/03/26/188784.html">快速修改 xdoclet samples ant -build.xml 适应实际开发</a><br />此文档为上面的改进版。<br /><br />1.在 你电脑上建一个 ant第三方扩展文件夹，我这为:D:\ant\lib<br />2.当使用 eclipse-&gt;window-&gt;proferences..-&gt;ant-&gt;Runtime-&gt;Global Entries-&gt;Add External JARs-&gt;选择你建的 ant_lib 下的全部jar;<br />3.并在Global Entries下加入你的 classpath <br /><br />使用现成的 xdoclet ant -&gt; 加入自己的 -&gt;<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">target </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="hbm2ddl"</span><span style="color: rgb(255, 0, 0);"> depends</span><span style="color: rgb(0, 0, 255);">="prepare"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">mkdir </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${hbm2ddl.sql.dir}"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">taskdef <br />              </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="hbm2ddl"</span><span style="color: rgb(255, 0, 0);"><br />             classname</span><span style="color: rgb(0, 0, 255);">="org.hibernate.tool.ant.HibernateToolTask"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">taskdef</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">hbm2ddl </span><span style="color: rgb(255, 0, 0);">destdir</span><span style="color: rgb(0, 0, 255);">="${hbm2ddl.sql.dir}"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">configuration </span><span style="color: rgb(255, 0, 0);">configurationfile</span><span style="color: rgb(0, 0, 255);">="../src/hibernate.cfg.xml"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />                   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">hbm2ddl </span><span style="color: rgb(255, 0, 0);">export</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(255, 0, 0);"> console</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> create</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> update</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> drop</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> outputfilename</span><span style="color: rgb(0, 0, 255);">="bestunix.sql"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">hbm2ddl</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />          <font color="#006400"> &lt;!-- 支持 1.5 泛型请 </font></span><font color="#006400">搜索到xjavadoc最新1.5版本，下载，替换原来的xjavadoc-1.1.x，再次运行xdoclet任务，执行成功！</font><span style="color: rgb(0, 0, 0);"><font color="#006400"> --&gt;</font><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">target</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">target </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="sql"</span><span style="color: rgb(255, 0, 0);"> depends</span><span style="color: rgb(0, 0, 255);">="hbm2ddl"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        <br />         </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">sql </span><span style="color: rgb(255, 0, 0);">driver</span><span style="color: rgb(0, 0, 255);">="org.gjt.mm.mysql.Driver"</span><span style="color: rgb(255, 0, 0);"> password</span><span style="color: rgb(0, 0, 255);">=""</span><span style="color: rgb(255, 0, 0);">  userid</span><span style="color: rgb(0, 0, 255);">="root"</span><span style="color: rgb(255, 0, 0);"> autocommit</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(255, 0, 0);">  <br />                       url</span><span style="color: rgb(0, 0, 255);">="jdbc:mysql://localhost:3306/zhongqi?characterEncoding=gbk"</span><span style="color: rgb(255, 0, 0);"> <br />                        src</span><span style="color: rgb(0, 0, 255);">="../sql/data.sql"</span><span style="color: rgb(255, 0, 0);"> print</span><span style="color: rgb(0, 0, 255);">="yes"</span><span style="color: rgb(255, 0, 0);"> output</span><span style="color: rgb(0, 0, 255);">="sql_out.txt"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  <br />              </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">sql</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  <br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">target</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">    </span></div><br />成功后就可以：<br />    使用 xdoclet 面向对象建表 ；<br />    通过 ant -&gt; java2hbn, hbn2ddl,insertSql <br /><br />在开发过程中当要加 jar 方法为： <br />    1.在 ant_lib 中加入 jar<br />    2.eclipse -&gt;&gt; Global Entries-&gt;Add External JARs-&gt;<br />工程转换修改 Global Entries中的classpath<br /><br />例：<br />java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> hbm;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.Set;<br /><br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /> * @hibernate.class table = "level"<br /> * where = " visible = 0  "<br /> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> Administrator<br /> *<br /> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Level {<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> id ;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String name ;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Level father ;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Set</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Level</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> childSet ;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> visible  ;<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Level(){}<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Level(String name){  </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> name ; }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Level(String name,</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> visible){</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.visible </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> visible;  </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> name ; }<br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * @hibernate.id generator-class = "identity"<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> getId() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> id;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setId(</span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> id) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.id </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> id;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * @hibernate.property <br />     * length = "20"<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> String getName() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> name;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setName(String name) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> name;<br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * @hibernate.many-to-one <br />     * cascade = "save-update"<br />     * inverse = "false"<br />     * column = "fid"<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Level getFather() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> father;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setFather(Level father) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.father </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> father;<br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * @hibernate.set <br />     * lazy = "true"<br />     * table = "Level"<br />     * cascade = "save-update"<br />     * where = " visible = 0 "<br />     * @hibernate.collection-key column = "fid"<br />     * @hibernate.collection-one-to-many class = "hbm.Level"<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Set</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Level</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> getChildSet() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> childSet;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setChildSet(Set</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Level</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> childSet) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.childSet </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> childSet;<br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * @hibernate.property <br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> getVisible() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> visible;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setVisible(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> visible) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.visible </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> visible;<br />    }<br />}<br /></span></div><br /><br />unit<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.HashSet;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.List;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.Set;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> hbm.Level;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.hibernate.Hibernate;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.hibernate.Session;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.hibernate.Transaction;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.junit.Test;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> unit.HibernateUtil;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HbnUnit {<br />    @Test<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> level() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        Session session </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> HibernateUtil.currentSession();<br />        Transaction tr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  session.beginTransaction();<br />        <br />        Level level </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level();<br />        level.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">f1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        <br />        Set</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Level</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> set </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashSet</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Level</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">();<br />            set.add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            set.add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">));<br />            set.add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            set.add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c4</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ));<br />            set.add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c5</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ));<br />            set.add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Level(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">c6</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ));<br />        <br />        level.setChildSet(set);<br />        session.save(level);<br />        session.flush() ;<br />        session.clear();<br />        tr.commit();<br /><br />        <br />    }<br />    <br />    @Test<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> sAll() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        Session session </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> HibernateUtil.currentSession();<br />        <br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">---------------------------------------------</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        List</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Level</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> list </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  session.createQuery(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> from Level tl where tl.father is null </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).list();<br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">( Level tmp : list ){<br />            System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">----&gt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> tmp.getName()</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> visible=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">tmp.getVisible()  );<br />            <br />            </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(  Level tt : tmp.getChildSet() ){<br />                System.out.println( tt.getName()</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> visible=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">tt.getVisible()  );<br />            }<br />            <br />        }<br />        System.out.println( list.get(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">).getVisible()</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> list.size() );<br />    }<br />    <br />}<br /></span></div><br />结果：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Hibernate: </span><span style="color: rgb(0, 0, 255);">insert</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">level</span><span style="color: rgb(0, 0, 0);"> (name, fid, visible) </span><span style="color: rgb(0, 0, 255);">values</span><span style="color: rgb(0, 0, 0);"> (?, ?, ?)<br />Hibernate: </span><span style="color: rgb(0, 0, 255);">insert</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">level</span><span style="color: rgb(0, 0, 0);"> (name, fid, visible) </span><span style="color: rgb(0, 0, 255);">values</span><span style="color: rgb(0, 0, 0);"> (?, ?, ?)<br />Hibernate: </span><span style="color: rgb(0, 0, 255);">insert</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">level</span><span style="color: rgb(0, 0, 0);"> (name, fid, visible) </span><span style="color: rgb(0, 0, 255);">values</span><span style="color: rgb(0, 0, 0);"> (?, ?, ?)<br />Hibernate: </span><span style="color: rgb(0, 0, 255);">insert</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">level</span><span style="color: rgb(0, 0, 0);"> (name, fid, visible) </span><span style="color: rgb(0, 0, 255);">values</span><span style="color: rgb(0, 0, 0);"> (?, ?, ?)<br />Hibernate: </span><span style="color: rgb(0, 0, 255);">insert</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> </span><span style="colo