📄 struts+hibernate(dao)+filter的例子.mht
字号:
#6666ff">//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"></SPAN=
>=20
<BR><BR><hibernate-mapping> <BR> =
=20
<<SPAN style=3D"FONT-WEIGHT: bold; COLOR: =
#990066"=20
?>class</SPAN> name=3D"com.<SPAN=20
style=3D"COLOR: #000000">foxconn</SPAN>.<SPAN=20
style=3D"COLOR: #000000">hibernate</SPAN>.<SPAN=20
style=3D"COLOR: #000000">po</SPAN>.<SPAN=20
style=3D"COLOR: #000000">Company</SPAN>" =
table=3D"company"=20
dynamic-update=3D"<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>false</SPAN>"> <BR> =
=20
<id name=3D"id" column=3D"id" type=3D"string" =
unsaved-value=3D"any" > <BR> =
=20
<generator <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>class</SPAN>=3D"assigned"> <BR> =
=20
</generator> =
<BR> =20
</id> <BR> =
=20
<property name=3D"companyname"=20
type=3D"string" update=3D"<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>true</SPAN>"=20
insert=3D"<SPAN style=3D"FONT-WEIGHT: bold; =
COLOR: #990066"=20
?>true</SPAN>" column=3D"company_name"/> =
<BR> =20
</<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>class</SPAN>>=20
=
<BR></hibernate-mapping></DIV><BR></TD></TR></TBODY></TABLE><SPAN=20
=
class=3Dpostbody><BR><BR>=C5=E4=D6=C3=CE=C4=BC=FEhibernate.cfg.xml =
<BR></SPAN>
<TABLE cellSpacing=3D1 cellPadding=3D3 width=3D"90%" =
align=3Dcenter=20
border=3D0>
<TBODY>
<TR>
<TD><SPAN =
class=3Dgenmed><B>java=B4=FA=C2=EB: </B></SPAN></TD></TR>
<TR>
<TD class=3Dcode>
<DIV=20
style=3D"FONT-FAMILY: 'Courier New', Courier, =
monospace"><BR><!DOCTYPE=20
hibernate-configuration <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>PUBLIC</SPAN> "-<SPAN=20
style=3D"COLOR: #6666ff">//Hibernate/Hibernate=20
Configuration D</SPAN> <BR><BR>TD<SPAN=20
style=3D"COLOR: #6666ff">//EN"=20
=
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"></S=
PAN>=20
<BR><BR><hibernate-configuration>=20
<BR><BR><session-factory> =
<BR><BR><property=20
name=3D"connection.<SPAN=20
style=3D"COLOR: =
#000000">datasource</SPAN>">java:comp/env/jdbc/fox221</property>=
=20
<BR><BR><property name=3D"show_sql"><SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>false</SPAN></property> =
<BR><BR><property=20
name=3D"dialect">net.<SPAN=20
style=3D"COLOR: #000000">sf</SPAN>.<SPAN=20
style=3D"COLOR: #000000">hibernate</SPAN>.<SPAN=20
style=3D"COLOR: #000000">dialect</SPAN>.<SPAN=20
style=3D"COLOR: =
#000000">OracleDialect</SPAN></property>=20
<BR><BR><property name=3D"jdbc.<SPAN=20
style=3D"COLOR: =
#000000">fetch_size</SPAN>"><SPAN=20
style=3D"COLOR: #000000" =
?>50</SPAN></property>=20
<BR><BR><property name=3D"jdbc.<SPAN=20
style=3D"COLOR: =
#000000">batch_size</SPAN>"><SPAN=20
style=3D"COLOR: #000000" =
?>30</SPAN></property>=20
<BR><BR><!-- Mapping files --> =
<BR><BR><mapping=20
resource=3D"/hbm/Company.<SPAN=20
style=3D"COLOR: #000000">hbm</SPAN>.<SPAN=20
style=3D"COLOR: #000000">xml</SPAN>"/>=20
<BR><BR></session-factory>=20
=
<BR><BR></hibernate-configuration></DIV><BR></TD></TR></TBODY></TAB=
LE><SPAN=20
=
class=3Dpostbody><BR><BR>=CC=E1=B9=A9session=B5=C4=C0=E0HebernateSessionF=
actory(=C0=FB=D3=C3Thread=B9=DC=C0=EDsession)=20
<BR><BR></SPAN>
<TABLE cellSpacing=3D1 cellPadding=3D3 width=3D"90%" =
align=3Dcenter=20
border=3D0>
<TBODY>
<TR>
<TD><SPAN =
class=3Dgenmed><B>java=B4=FA=C2=EB: </B></SPAN></TD></TR>
<TR>
<TD class=3Dcode>
<DIV=20
style=3D"FONT-FAMILY: 'Courier New', Courier, =
monospace"><BR><SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>public</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>class</SPAN>=20
HibernateSessionFactory <SPAN=20
style=3D"COLOR: #000000">{</SPAN> <BR> =
<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>public</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>static</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>final</SPAN>=20
<SPAN style=3D"COLOR: #aaaadd" =
?>ThreadLocal</SPAN>=20
session =3D <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>new</SPAN>=20
<SPAN style=3D"COLOR: #aaaadd" =
?>ThreadLocal</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>private</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>static</SPAN> SessionFactory sessionFactory;=20
<BR><BR> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>static</SPAN> <SPAN style=3D"COLOR: =
#000000">{</SPAN>=20
<BR> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>try</SPAN>=20
<SPAN style=3D"COLOR: #000000">{</SPAN> =
<BR> =20
sessionFactory =3D =
<BR> =20
=
=20
<SPAN style=3D"FONT-WEIGHT: bold; COLOR: =
#990066"=20
?>new</SPAN> Configuration<SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>.<SPAN=20
style=3D"COLOR: #000000">configure</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>.<SPAN=20
style=3D"COLOR: =
#000000">buildSessionFactory</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
=20
<SPAN style=3D"COLOR: =
#000000">}</SPAN>=20
<SPAN style=3D"FONT-WEIGHT: bold; COLOR: =
#990066"=20
?>catch</SPAN> <SPAN=20
style=3D"COLOR: =
#000000">(</SPAN>HibernateException=20
ex<SPAN style=3D"COLOR: #000000">)</SPAN> <SPAN=20
style=3D"COLOR: #000000">{</SPAN> <BR> =
=20
throw <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>new</SPAN>=20
<SPAN style=3D"COLOR: #aaaadd"=20
?>RuntimeException</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN> <BR> =
=20
=
"<SPAN=20
style=3D"COLOR: #aaaadd" ?>Exception</SPAN> =
building=20
SessionFactory: " + ex.<SPAN=20
style=3D"COLOR: #000000">getMessage</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>,ex<SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
=20
<SPAN style=3D"COLOR: =
#000000">}</SPAN>=20
<BR> <SPAN style=3D"COLOR: =
#000000">}</SPAN>=20
<BR><BR> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>public</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>static</SPAN> Session currentSession<SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>throws</SPAN> HibernateException<SPAN=20
style=3D"COLOR: #000000">{</SPAN> <BR> =
=20
Session s =3D =
<SPAN=20
style=3D"COLOR: #000000">(</SPAN>Session<SPAN=20
style=3D"COLOR: #000000">)</SPAN> session.<SPAN=20
style=3D"COLOR: #000000">get</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
=20
<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>if</SPAN>=20
<SPAN style=3D"COLOR: #000000">(</SPAN>s =3D=3D =
<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>null</SPAN><SPAN style=3D"COLOR: =
#000000">)</SPAN> <SPAN=20
style=3D"COLOR: #000000">{</SPAN> <BR> =
=20
=
s=20
=3D sessionFactory.<SPAN=20
style=3D"COLOR: #000000">openSession</SPAN><SPAN =
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
=20
=
=20
session.<SPAN style=3D"COLOR: =
#000000">set</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN>s<SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
=20
<SPAN=20
style=3D"COLOR: #000000">}</SPAN> <BR> =
=20
<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>return</SPAN> s; <BR> <SPAN=20
style=3D"COLOR: #000000">}</SPAN> <BR> =
<SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>public</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>static</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066" =
?>void</SPAN>=20
closeSession<SPAN style=3D"COLOR: =
#000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN> <SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
?>throws</SPAN> HibernateException<SPAN=20
style=3D"COLOR: #000000">{</SPAN> <BR> =
=20
Session s =3D <SPAN=20
style=3D"COLOR: #000000">(</SPAN>Session<SPAN=20
style=3D"COLOR: #000000">)</SPAN> session.<SPAN=20
style=3D"COLOR: #000000">get</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"COLOR: #000000">)</SPAN>; <BR> =
=20
session.<SPAN=20
style=3D"COLOR: #000000">set</SPAN><SPAN=20
style=3D"COLOR: #000000">(</SPAN><SPAN=20
style=3D"FONT-WEIGHT: bold; COLOR: #990066"=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -