﻿<?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-飞翔吧-随笔分类-DataBase</title><link>http://www.blogjava.net/ytfei/category/3101.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 03:08:11 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 03:08:11 GMT</pubDate><ttl>60</ttl><item><title>Hibernate In Action Note</title><link>http://www.blogjava.net/ytfei/archive/2005/09/05/12119.html</link><dc:creator>飞翔</dc:creator><author>飞翔</author><pubDate>Mon, 05 Sep 2005 14:14:00 GMT</pubDate><guid>http://www.blogjava.net/ytfei/archive/2005/09/05/12119.html</guid><wfw:comment>http://www.blogjava.net/ytfei/comments/12119.html</wfw:comment><comments>http://www.blogjava.net/ytfei/archive/2005/09/05/12119.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ytfei/comments/commentRss/12119.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ytfei/services/trackbacks/12119.html</trackback:ping><description><![CDATA[1.(Hibernate with a connection pool in a non-managed environment)<BR>Using hibernate.properties for C3P0 connection pool settings:<BR>hibernate.connection.driver_class = org.postgresql.Driver<BR>hibernate.connection.url = jdbc:postgresql://localhost/auctiondb<BR>hibernate.connection.username = auctionuser<BR>hibernate.connection.password = secret<BR>hibernate.dialect = net.sf.hibernate.dialect.PostgreSQLDialect<BR>hibernate.c3p0.min_size=5<BR>hibernate.c3p0.max_size=20<BR>hibernate.c3p0.timeout=300<BR>hibernate.c3p0.max_statements=50<BR>hibernate.c3p0.idle_test_period=3000<BR>2.(Hibernate in a managed environment with an application server) <BR>hibernate.connection.datasource = java:/comp/env/jdbc/AuctionDB<BR>hibernate.transaction.factory_class = \<BR>net.sf.hibernate.transaction.JTATransactionFactory<BR>hibernate.transaction.manager_lookup_class = \<BR>net.sf.hibernate.transaction.JBossTransactionManagerLookup<BR>hibernate.dialect = net.sf.hibernate.dialect.PostgreSQLDialect<BR><BR>结合spring 后就不是这样了，可以右spring 控制transaction &amp; datasource &amp;...<img src ="http://www.blogjava.net/ytfei/aggbug/12119.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ytfei/" target="_blank">飞翔</a> 2005-09-05 22:14 <a href="http://www.blogjava.net/ytfei/archive/2005/09/05/12119.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts menu的使用（动态数据）</title><link>http://www.blogjava.net/ytfei/archive/2005/08/30/12079.html</link><dc:creator>飞翔</dc:creator><author>飞翔</author><pubDate>Tue, 30 Aug 2005 03:42:00 GMT</pubDate><guid>http://www.blogjava.net/ytfei/archive/2005/08/30/12079.html</guid><wfw:comment>http://www.blogjava.net/ytfei/comments/12079.html</wfw:comment><comments>http://www.blogjava.net/ytfei/archive/2005/08/30/12079.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ytfei/comments/commentRss/12079.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ytfei/services/trackbacks/12079.html</trackback:ping><description><![CDATA[&nbsp;以下是我在实际项目中使用了struts-menu，现将他们写出来已供参考<BR>1.<BR><SPAN>&nbsp;&nbsp; 拷贝必要的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">jar</FONT></SPAN><SPAN>库文件到</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">dbMenu\WEB-INF\lib</FONT></SPAN> <BR><FONT face="Times New Roman"><FONT size=2><SPAN lang=EN-US>log4j-</SPAN><?xml:namespace prefix = st1 /><st1:chsdate Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False"><SPAN lang=EN-US>1.2.8</SPAN></st1:chsdate><SPAN lang=EN-US>.jar<BR></SPAN></FONT></FONT><FONT size=2><SPAN lang=EN-US><FONT face="Times New Roman">struts-menu-2.3.jar</FONT></SPAN><SPAN lang=EN-US><FONT face="Times New Roman">&nbsp;<BR>拷贝menu-config.xml&nbsp;,struts-menu.tld 到WEB-INF目录下,<BR>及一些必须的图片和jscript,css到相应的目录<BR>Images/*.*&nbsp;<SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=2><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR></SPAN>Scripts/<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>menuExpandable.js xtree.js<BR></FONT></FONT></SPAN><SPAN lang=EN-US><FONT face="Times New Roman"><FONT size=2>Styles/<SPAN>&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>menuExpandable.css<SPAN>&nbsp;&nbsp; </SPAN>global.css<SPAN>&nbsp;&nbsp; </SPAN>xtree.css</FONT></FONT></SPAN><BR>2.<BR><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">修改</SPAN><SPAN lang=EN-US>struts-config.xml </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>增加如下部分</FONT> 
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">plug-in&nbsp;</SPAN><SPAN style="COLOR: #ff0000">className</SPAN><SPAN style="COLOR: #0000ff">="net.sf.navigator.menu.MenuPlugIn"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">set-property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">property</SPAN><SPAN style="COLOR: #0000ff">="menuConfig"</SPAN></FONT><SPAN style="COLOR: #ff0000"><BR><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">="/WEB-INF/menu-config.xml"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR><FONT size=2>&nbsp;&nbsp;&nbsp;</FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff"></< SPAN><SPAN style="COLOR: #800000">plug-in</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN></DIV></DIV>
<P></SPAN></FONT></SPAN></FONT>3.获得数据,构造树状菜单：<BR>&nbsp; 无论何种方法获得数据（JDBC，HIBERNATE。。。），<BR>&nbsp;&nbsp;&nbsp; 我们要构造的树状菜单需要2个必须元素: 1.显示的名称(name) 2.连接到的目标位置(location)<BR>&nbsp; TreeBuilder.java<BR>===========================================================================<BR><BR>/*<BR>&nbsp;* 创建日期 2005-8-6<BR>&nbsp;*/<BR>import ....</P>
<P>import net.sf.navigator.menu.MenuComponent;<BR>import net.sf.navigator.menu.MenuRepository;</P>
<P>/**<BR>&nbsp;* @author yutengfei<BR>&nbsp;*/<BR>public class TreeBuilder {<BR>&nbsp;protected final static Log log = LogFactory.getLog("TreeBuilder");&nbsp;<BR>&nbsp;public TreeBuilder() {&nbsp;}</P>
<P>&nbsp;// 以下代码生成树结构，并以"treerepository"名储存在session&nbsp;中<BR>&nbsp;&nbsp;&nbsp;public static void initialTree(HttpServletRequest request, HttpServlet servlet){<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;MenuRepository repository = new MenuRepository();<BR>&nbsp;&nbsp; ServletContext context = servlet.getServletContext()<BR>&nbsp;&nbsp;&nbsp;// Get the repository from the application scope - and copy the<BR>&nbsp;&nbsp;&nbsp;// DisplayerMappings from it.<BR>&nbsp;&nbsp;&nbsp;MenuRepository defaultRepository = (MenuRepository) context.getAttribute(MenuRepository.MENU_REPOSITORY_KEY);</P>
<P>&nbsp;&nbsp;&nbsp;repository.setDisplayers(defaultRepository.getDisplayers());&nbsp;<BR><BR>//your&nbsp;code begin <BR>List tree = getTreeDataFromDataBase(); //<BR>//&nbsp;产生从数据库中获得的数据列表(一个树节点是一个<FONT size=2>NoteBean </FONT>对象)&nbsp;，获得数据的方法这里没有提供<BR>for(Iterator it = tree.iterator();it.hasNext();)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MenuComponent&nbsp;mc&nbsp;<SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><FONT size=2><SPAN style="COLOR: #000000">&nbsp;MenuComponent();&nbsp;&nbsp; //建立一个menu对象(树节点)，然后设置他的属性<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NoteBean row&nbsp;</SPAN><SPAN style="COLOR: #000000">=(NoteBean) it.next()</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;name&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(String)&nbsp;row.</SPAN><SPAN style="COLOR: #0000ff">getN</SPAN><SPAN style="COLOR: #000000">ame()</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mc.setName(name);&nbsp; //设置显示的节点名称<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;parent&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(String)&nbsp;row.</SPAN><SPAN style="COLOR: #0000ff">getP</SPAN><SPAN style="COLOR: #000000">arentname()</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(name&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;parent&nbsp;is:&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;parent);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(parent&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)&nbsp;{//存在“父”节点<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MenuComponent&nbsp;parentMenu&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;repository.getMenu(parent);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(parentMenu&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">parentMenu&nbsp;'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;parent&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">'&nbsp;doesn't&nbsp;exist!</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;create&nbsp;a&nbsp;temporary&nbsp;parentMenu</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parentMenu&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;MenuComponent();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parentMenu.setName(parent);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;repository.addMenu(parentMenu);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mc.setParent(parentMenu);&nbsp;&nbsp; //设置“父”节点<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;title&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(String)&nbsp;row.</SPAN><SPAN style="COLOR: #0000ff">getT</SPAN><SPAN style="COLOR: #000000">itle()</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mc.setTitle(title);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;location&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(String)&nbsp;row.</SPAN><SPAN style="COLOR: #0000ff">getL</SPAN><SPAN style="COLOR: #000000">ocation()</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mc.setLocation(location);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;repository.addMenu(mc);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></FONT>&nbsp;&nbsp;&nbsp;<BR>request.getSession().setAttribute("treerepository", repository);&nbsp;&nbsp; //整个树结构储存在session中<BR>&nbsp;&nbsp;} catch (Exception ex) {<BR>&nbsp;&nbsp;&nbsp;ex.printStackTrace();<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;}</P>
<P>}<BR><BR>4.前台jsp显示树菜单<BR><BR><%try{%><BR><%<BR>if (session.getAttribute("treerepository") == null) {<BR>TreeBuilder .initialTree(request, (HttpServlet) pageContext.getPage());<BR> }%><BR><%List list = new ArrayList();<BR>MenuRepository repository = (MenuRepository) session.getAttribute("treerepository");<BR>list = repository.getTopMenus();<BR>String name = "";%><BR>
<DIV class=dynamicMenu><?xml:namespace prefix = menu /><menu:useMenuDisplayer repository="treerepository" name="ListMenu"><BR>&nbsp;<%for (Iterator it = list.iterator(); it.hasNext();) {<BR> name = ((MenuComponent) it.next()).getName();%><BR>&nbsp;<menu:displayMenu name="<%=name%>"></menu:displayMenu><BR>&nbsp;<%}%><BR></menu:useMenuDisplayer></DIV><BR><%}catch(Exception e){<BR>e.printStackTrace();<BR>}<BR>%><BR><BR>5 over <BR>
<P></P><IMG height=1 src="http://ytfei.cnblogs.com/aggbug/225943.html" width=1><BR><BR>
<DIV align=right>飞翔 2005-08-30 11:42 </DIV><BR>文章来源:<A href="http://ytfei.cnblogs.com/archive/2005/08/30/225943.html">http://ytfei.cnblogs.com/archive/2005/08/30/225943.html</A></SPAN><img src ="http://www.blogjava.net/ytfei/aggbug/12079.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ytfei/" target="_blank">飞翔</a> 2005-08-30 11:42 <a href="http://www.blogjava.net/ytfei/archive/2005/08/30/12079.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>