﻿<?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-sword</title><link>http://www.blogjava.net/sword/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 28 Apr 2026 20:48:31 GMT</lastBuildDate><pubDate>Tue, 28 Apr 2026 20:48:31 GMT</pubDate><ttl>60</ttl><item><title>JRebel + Maven + Jetty 热部署(转)</title><link>http://www.blogjava.net/sword/archive/2010/05/23/321686.html</link><dc:creator>sw0rd</dc:creator><author>sw0rd</author><pubDate>Sun, 23 May 2010 14:28:00 GMT</pubDate><guid>http://www.blogjava.net/sword/archive/2010/05/23/321686.html</guid><wfw:comment>http://www.blogjava.net/sword/comments/321686.html</wfw:comment><comments>http://www.blogjava.net/sword/archive/2010/05/23/321686.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sword/comments/commentRss/321686.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sword/services/trackbacks/321686.html</trackback:ping><description><![CDATA[<p>早就厌烦了 Java 开发不断的容器自动重新加载漫长的过程，研究 maven + jetty 热部署方案的过程中偶然发现一样不错的东东，试用了一下果然很爽，发上来给大家共享，此物名为 JRebel (javarebel)，目前支持大部分主流的 Java 容器，配置也相当简单，以下是与 maven + jetty 环境整合的步骤与要点：</p>
<p>首先，下载 JRebel 包，目前网上有两个破解版本分别是 JRebel2.1a 以及 JRebel3.0-M1，我使用的是前者，下面是下载地址：http://d.namipan.com/d/842d40cc1ed226fc69e04892cdaeaec85cf85be105f41400 （需要的请尽快下载，以免链接失效）。</p>
<p>然后拷贝到 %REBEL_HOME% 目录并添加该环境变量，进入目录运行 java -jar %REBEL_HOME%\jrebel.jar 生成根据本机 JVM 环境生成的 jrebel-bootstrap.jar 运行文件。</p>
<p><br />
然后添加 MAVEN 运行环境变量：MAVEN_OPTS 值为 -noverify -Xbootclasspath/p:%REBEL_HOME%\jrebel-bootstrap.jar;%REBEL_HOME%\jrebel.jar 然后再配置目标项目的 pom.xml，关闭 maven 的 jetty 插件本身的 reload 配置：</p>
<p>&lt;plugin&gt;<br />
&lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;<br />
&lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;<br />
&lt;configuration&gt;<br />
&lt;scanIntervalSeconds&gt;0&lt;/scanIntervalSeconds&gt;<br />
&lt;/configuration&gt;<br />
&lt;/plugin&gt;</p>
<p>最后启动 mvn jetty:run 你会发现现在不需要 reload 服务器就可以加载实时修改过的 class 文件了，很不错吧。其实我个人更推荐不要设置 MAVEN_OPTS 环境变量，新建一个比如名为 mvnrebel.bat 的文件，改写一下 mvn.bat 文件，把以上的运行命令加进去，这样还保留了原本的 mvn 执行文件，同时也可以根据需要启动带热部署的方案。</p>
<p>JRefer 工具还提供其他各种主流环境的整合方案，包括 JBoss，Glassfish，Tomcat，SpringSource，Weblogic，SAP 等，详细内容请参考：http://www.zeroturnaround.com/reference-manual/server.html 对于开发人员来说，这无疑会大大减轻开发重新加载的问题，据调查平均可以提高 20% 的开发效率，效果相当的可观哦，有兴趣的朋友值得一试~</p>
<p>&nbsp;</p>
<p>本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/shagoo/archive/2010/04/26/5529352.aspx</p>
<img src ="http://www.blogjava.net/sword/aggbug/321686.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sword/" target="_blank">sw0rd</a> 2010-05-23 22:28 <a href="http://www.blogjava.net/sword/archive/2010/05/23/321686.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>国内和国外DNS服务器地址 全国各地电信DNS服务器地址(转)</title><link>http://www.blogjava.net/sword/archive/2009/07/01/284994.html</link><dc:creator>sw0rd</dc:creator><author>sw0rd</author><pubDate>Wed, 01 Jul 2009 09:56:00 GMT</pubDate><guid>http://www.blogjava.net/sword/archive/2009/07/01/284994.html</guid><wfw:comment>http://www.blogjava.net/sword/comments/284994.html</wfw:comment><comments>http://www.blogjava.net/sword/archive/2009/07/01/284994.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sword/comments/commentRss/284994.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sword/services/trackbacks/284994.html</trackback:ping><description><![CDATA[<div>全国各地电信DNS服务器地址</div>
<div>2007年04月10日 星期二 15:50</div>
<table style="table-layout: fixed">
    <tbody>
        <tr>
            <td>
            <div>北京：202.96.199.133 202.96.0.133 202.106.0.20 202.106.148.1 202.97.16.195<br />
            上海：202.96.199.132 202.96.199.133 202.96.209.5 202.96.209.133<br />
            天津：202.99.96.68 10.10.64.68<br />
            广东：202.96.128.143 202.96.128.68 202.96.128.110<br />
            深圳：202.96.134.133 202.96.154.8 202.96.154.15<br />
            河南：202.102.227.68 202.102.245.12 202.102.224.68<br />
            广西：202.96.128.68 202.103.224.68 202.103.225.68<br />
            福建：202.101.98.54 202.101.98.55<br />
            厦门：202.101.103.55 202.101.103.54<br />
            湖南：202.103.0.68 202.103.96.68 202.103.96.112<br />
            江苏：202.102.15.162 202.102.29.3 202.102.13.141 202.102.24.35<br />
            陕西：202.100.13.11 202.100.4.16<br />
            西安：202.100.4.15 202.100.0.68<br />
            湖北：202.103.0.68 202.103.0.117 202.103.24.68<br />
            山东：202.102.154.3 202.102.152.3 202.102.128.68 202.102.134.68<br />
            浙江：202.96.102.3 202.96.96.68 202.96.104.18<br />
            辽宁：202.98.0.68 202.96.75.68 202.96.75.64 202.96.69.38 202.96.86.18 202.96.86.24<br />
            安徽：202.102.192.68 202.102.199.68 10.89.64.5<br />
            重庆：61.128.128.68 10.150.0.1<br />
            黑龙江：202.97.229.133 202.97.224.68<br />
            河北：202.99.160.68 10.17.128.90<br />
            保定：202.99.160.68 202.99.166.4<br />
            吉林：202.98.5.68 202.98.14.18 202.98.14.19<br />
            江西：202.101.224.68 10.117.32.40 202.109.129.2 202.101.240.36<br />
            山西：202.99.192.68 202.99.198.6<br />
            新疆：61.128.97.74 61.128.97.73<br />
            贵州：202.98.192.68 10.157.2.15<br />
            云南：202.98.96.68 202.98.160.68<br />
            四川：202.98.96.68 61.139.2.69<br />
            重庆：61.128.128.68 61.128.192.4<br />
            成都：202.98.96.68 202.98.96.69<br />
            内蒙古：202.99.224.68 10.29.0.2<br />
            青海：202.100.128.68 10.184.0.1<br />
            海南：202.100.192.68 202.100.199.8<br />
            宁夏：202.100.0.68 202.100.96.68<br />
            甘肃：202.100.72.13 10.179.64.1<br />
            香港：205.252.144.228 208.151.69.65<br />
            澳门：202.175.3.8 202.175.3.3<br />
            <br />
            各大网站DNS列表
            <p>天府热线DNS：61.139.2.69 <br />
            长春163　　：202.98.0.68 <br />
            　　　　　　 202.98.3.68 <br />
            263在线　　：211.100.2.130 <br />
            　　　　　　 211.100.1.10 <br />
            中国万网　 ：210.79.232.248 <br />
            　　DNS　　：210.192.103.50　　 (dns1.hichina.com) <br />
            　　DNS　　：202.106.169.100　　(dns2.hichina.com) <br />
            新网　　　 ：211.99.199.194 <br />
            　　　　　 ：211.99.199.195 <br />
            263IDC　　 ：211.100.2.130　　(NS.263IDC.COM) <br />
            　　　　　 ：211.100.1.10 　　(NSB.263IDC.COM)</p>
            <p><br />
            教育网内的DNS服务器 <br />
            202.114.64.2武大DNS1 （一区） <br />
            202.114.96.1 武大DNS2 （二区） <br />
            202.114.96.2 武大DNS3 （二区） <br />
            202.114.112.13 武大DNS4 （三区）</p>
            <p>202.114.0.242 server20.hust.edu.cn 华工DNS <br />
            202.112.0.35 dns.hust.edu.cn 华工DNS2 <br />
            202.112.20.131 dns.whnet.edu.cn 华中地区网络中心DNS <br />
            166.111.8.28 dns-a.tsinghua.edu.cn清华DNS1 <br />
            166.111.8.29 dns-b.tsinghua.edu.cn清华DNS2 <br />
            166.111.8.30 dns.tsinghua.edu.cn 清华DNS <br />
            166.111.168.12清华DNS <br />
            202.117.0.20 dec3000.xjtu.edu.cn 西交DNS1 <br />
            202.117.0.21 ns2.xjtu.edu.cn 西交DNS2 <br />
            202.112.26.34上交 <br />
            202.112.112.100 人大 <br />
            162.105.129.27北大 <br />
            <br />
            202.203.128.33 cernet云南中心主dns <br />
            202.203.128.34 <br />
            202.115.64.33 and 202.115.64.34 西南交大 <br />
            202.201.48.1 and 202.201.48.2 nwnu <br />
            210.33.116.112 浙江电大 <br />
            202.116.160.33 华南农业 <br />
            202.114.240.6 wust <br />
            202.194.48.130 ytnc <br />
            202.112.0.33 and 202.112.0.34 cernet 华北网</p>
            <br />
            <br />
            全球路由DNS服务器<br />
            <br />
            全球只有13台路由DNS服务器（Route Server),在13台路由服务器中，名字分别为&#8220;A&#8221;至&#8220;M&#8221;，其中10台设置在美国，另外各有一台设置于英国、瑞典和日本。下表是这些机器的管理单位、设置地点及最新的IP地址。http://koogou.net其中，IP地址等参考了&#8220;named.root&#8221;文件:<br />
            <br />
            名称　　管理单位及设置地点　　　　IP地址<br />
            <br />
            A INTERNIC.NET（美国，弗吉尼亚州） 198.41.0.4<br />
            <br />
            B 美国信息科学研究所（美国，加利弗尼亚州） 128.9.0.107<br />
            <br />
            C PSINet公司（美国，弗吉尼亚州） 192.33.4.12<br />
            <br />
            D 马里兰大学（美国马里兰州） 128.8.10.90<br />
            <br />
            E 美国航空航天管理局[NASA]（美国加利弗尼亚州） 192.203.230.10<br />
            <br />
            F 因特网软件联盟（美国加利弗尼亚州） 192.5.5.241<br />
            <br />
            G 美国国防部网络信息中心（美国弗吉尼亚州） 192.112.36.4<br />
            <br />
            H 美国陆军研究所（美国马里兰州） 128.63.2.53<br />
            <br />
            I Autonomica公司（瑞典，斯德哥尔摩） 192.36.148.17<br />
            <br />
            J VeriSign公司（美国，弗吉尼亚州） 192.58.128.30<br />
            <br />
            K RIPE NCC（英国，伦敦） 193.0.14.129<br />
            <br />
            L IANA （美国，弗吉尼亚州） 198.32.64.12<br />
            <p>新西兰<br />
            202.27.184.3</p>
            <p>美国<br />
            165.87.13.129<br />
            165.87.201.244<br />
            205.171.3.65<br />
            205.171.2.65<br />
            198.41.0.4<br />
            198.41.0.4<br />
            198.32.64.12<br />
            192.33.4.12<br />
            192.203.230.10<br />
            192.5.5.241<br />
            192.112.36.4<br />
            192.36.148.17<br />
            192.58.128.30<br />
            192.9.9.3<br />
            193.0.14.129<br />
            128.9.0.107<br />
            128.8.10.90</p>
            <p><br />
            加拿大<br />
            209.166.160.36<br />
            209.166.160.132</p>
            <p>泰国<br />
            202.44.8.34<br />
            202.44.8.2</p>
            <p><br />
            印度<br />
            202.138.103.100<br />
            202.138.96.2</p>
            <p>香港<br />
            205.252.144.228</p>
            <p><br />
            英国<br />
            193.0.14.129</p>
            <p>日本<br />
            202.12.27.33<br />
            202.216.228.18 <br />
            202.27.184.3（新西兰）</p>
            <p>165.87.13.129 <br />
            165.87.201.244（美国）</p>
            <p>209.166.160.36<br />
            209.166.160.132（加拿大）</p>
            <p>202.44.8.34（泰国）<br />
            202.44.8.2</p>
            <p>205.171.3.65（美国）<br />
            205.171.2.65</p>
            <p>202.138.103.100印度<br />
            202.138.96.2</p>
            <p>202.106.0.20北京<br />
            202.96.209.5上海<br />
            205.252.144.228香港<br />
            &nbsp;解决国内不能正常访问GMAIL的方法 <br />
            http://www.bokee.com/idea/gmail-fyf/</p>
            <p>不能正常访问GMAIL，是由于国内网关上有检查设备和DNS劫持，这些设备干什么用的，我就不多说了。 </p>
            <p>要想正常访问GMAIL主要有几点：</p>
            <p>1、选择正确的DNS服务器，我发现主DNS设置成国外根服务器的DNS，然后辅助DNS设置成国外的DNS，就可以正常的解析了。 </p>
            <p>具体做法： </p>
            <p>在拨号网络或网卡属性里设置</p>
            <p>主DNS设成 202.12.27.33 </p>
            <p>辅助DNS：202.216 .228.18 (日本DNS) 大家还可以自己找一些快的国外DNS。 </p>
            <p>2、要用https，也就是用加密协议来访问GMAIL <br />
            </p>
            <br />
            <br />
            <p>香港：205.252.144.228 <br />
            208.151.69.65<br />
            202.181.202.140<br />
            202.181.224.2&nbsp; <br />
            &nbsp;<br />
            台湾168.95.192.1<br />
            168.95.1.1 <br />
            &nbsp;<br />
            澳门：202.175.3.8 <br />
            202.175.3.3<br />
            &nbsp;<br />
            各大网站DNS列表 </p>
            <p>天府热线DNS：61.139.2.69 </p>
            <p>长春163　　：202.98.0.68 <br />
            　　　　　　 202.98.3.68 </p>
            <p>263在线　　：211.100.2.130 <br />
            　　　　　　 211.100.1.10 </p>
            <p>中国万网　 ：210.79.232.248 <br />
            　　DNS　　：210.192.103.50　　 (dns1.hichina.com) <br />
            　　DNS　　：202.106.169.100　　(dns2.hichina.com) </p>
            <p>新网　　　 ：211.99.199.194 <br />
            　　　　　 ：211.99.199.195 </p>
            <p>263IDC　　 ：211.100.2.130　　(NS.263IDC.COM) <br />
            　　　　　 ：211.100.1.10 　　(NSB.263IDC.COM)</p>
            <p>教育网内的DNS服务器 <br />
            202.114.64.2武大DNS1 （一区） <br />
            202.114.96.1 武大DNS2 （二区） <br />
            202.114.96.2 武大DNS3 （二区） <br />
            202.114.112.13 武大DNS4 （三区）<br />
            202.114.0.242 server20.hust.edu.cn 华工DNS <br />
            202.112.0.35 dns.hust.edu.cn 华工DNS2 <br />
            202.112.20.131 dns.whnet.edu.cn 华中地区网络中心DNS <br />
            166.111.8.28 dns-a.tsinghua.edu.cn清华DNS1 <br />
            166.111.8.29 dns-b.tsinghua.edu.cn清华DNS2 <br />
            166.111.8.30 dns.tsinghua.edu.cn 清华DNS <br />
            166.111.168.12清华DNS <br />
            202.117.0.20 dec3000.xjtu.edu.cn 西交DNS1 <br />
            202.117.0.21 ns2.xjtu.edu.cn 西交DNS2 <br />
            202.112.26.34上交 <br />
            202.112.112.100 人大 <br />
            162.105.129.27北大 <br />
            202.203.128.33 cernet云南中心主dns <br />
            202.203.128.34 <br />
            202.115.64.33 and 202.115.64.34 西南交大 <br />
            202.201.48.1 and 202.201.48.2 nwnu <br />
            210.33.116.112 浙江电大 <br />
            202.116.160.33 华南农业 <br />
            202.114.240.6 wust <br />
            202.194.48.130 ytnc <br />
            202.112.0.33 and 202.112.0.34 cernet 华北网<br />
            &nbsp;<br />
            全球路由DNS服务器<br />
            全球只有13台路由DNS服务器（Route Server),在13台路由服务器中，名字分别为&#8220;A&#8221;至&#8220;M&#8221;，其中10台设置在美国，另外各有一台设置于英国、瑞典和日本。下表是这些机器的管理单位、设置地点及最新的IP地址。[url]http://koogou.net[/url]其中，IP地址等参考了&#8220;named.root&#8221;文件:<br />
            名称　　管理单位及设置地点　　　　IP地址<br />
            A INTERNIC.NET（美国，弗吉尼亚州） 198.41.0.4<br />
            B 美国信息科学研究所（美国，加利弗尼亚州） 128.9.0.107<br />
            C PSINet公司（美国，弗吉尼亚州） 192.33.4.12<br />
            D 马里兰大学（美国马里兰州） 128.8.10.90<br />
            E 美国航空航天管理局[NASA]（美国加利弗尼亚州） 192.203.230.10<br />
            F 因特网软件联盟（美国加利弗尼亚州） 192.5.5.241<br />
            G 美国国防部网络信息中心（美国弗吉尼亚州） 192.112.36.4<br />
            H 美国陆军研究所（美国马里兰州） 128.63.2.53<br />
            I Autonomica公司（瑞典，斯德哥尔摩） 192.36.148.17<br />
            J VeriSign公司（美国，弗吉尼亚州） 192.58.128.30<br />
            K RIPE NCC（英国，伦敦） 193.0.14.129<br />
            L IANA （美国，弗吉尼亚州） 198.32.64.12<br />
            &nbsp;<br />
            新西兰<br />
            202.27.184.3<br />
            &nbsp;<br />
            美国<br />
            165.87.13.129<br />
            165.87.201.244<br />
            205.171.3.65<br />
            205.171.2.65<br />
            198.41.0.4<br />
            198.41.0.4<br />
            198.32.64.12<br />
            192.33.4.12<br />
            192.203.230.10<br />
            192.5.5.241<br />
            192.112.36.4<br />
            192.36.148.17<br />
            192.58.128.30<br />
            192.9.9.3<br />
            193.0.14.129<br />
            128.9.0.107<br />
            128.8.10.90<br />
            66.33.206.206.<br />
            208.96.10.221<br />
            66.33.216.216<br />
            208.67.222.222<br />
            208.67.220.220<br />
            205.171.3.65<br />
            205.171.2.65<br />
            165.87.13.129 <br />
            165.87.201.244<br />
            208.67.222.222<br />
            208.67.220.220</p>
            <p>加拿大<br />
            209.166.160.36<br />
            209.166.160.132<br />
            &nbsp;<br />
            泰国<br />
            202.44.8.34<br />
            202.44.8.2</p>
            <p>印度<br />
            202.138.103.100<br />
            202.138.96.2</p>
            <p>英国<br />
            193.0.14.129<br />
            &nbsp;<br />
            日本<br />
            202.12.27.33<br />
            202.216.228.18 <br />
            &nbsp;<br />
            韩国<br />
            164.124.101.31<br />
            203.248.240.31<br />
            168.126.63.60<br />
            168.126.63.61</p>
            <p>&nbsp;<br />
            新西兰202.27.184.3<br />
            &nbsp;<br />
            加拿大209.166.160.36<br />
            &nbsp;<br />
            泰国209.166.160.132<br />
            202.44.8.34<br />
            202.44.8.2</p>
            <br />
            <br />
            <br />
            最近公司的电信光线使用过程中发现有时连接国外总公司服务器延时很大，而且有丢包，所以联系服务商调整路由，不走南方电信的公网而走南方网通的路由，结果发现ping的时候延时很正常也没有丢包。但是，只有邮件服务器从调整路由起就发送不到国外那个服务器上了。很奇怪，开始便怀疑是DNS设置的问题。随后更改了几个电信和香港、台湾的DNS结果还是不行。因此收集了几个网通的DNS试试：<br />
            &nbsp;<br />
            网通 B北京 202.106.0.20, 202.106.196.115&nbsp; <br />
            网通 G广西 202.103.229.40, 221.7.128.68&nbsp; <br />
            网通 H海南 221.11.132.2&nbsp; <br />
            网通 H河北 202.99.160.68, 202.99.166.4&nbsp; <br />
            网通 H黑龙江 202.97.224.68, 202.97.224.69&nbsp; <br />
            网通 H河南 202.102.224.68, 202.102.227.68&nbsp; <br />
            网通 H湖北 218.104.111.112, 218.104.111.114&nbsp; <br />
            网通 J江苏 221.6.4.66, 221.6.96.177&nbsp; <br />
            网通 J吉林 202.98.0.68, 202.98.5.68&nbsp; <br />
            网通 L辽宁 202.96.69.38, 202.96.64.68&nbsp; <br />
            网通 N内蒙古 202.99.224.8, 202.99.224.67, 202.99.224.68&nbsp; <br />
            网通 S山东 202.102.152.3, 202.102.134.68&nbsp; <br />
            网通 S上海 210.22.70.3, 210.22.70.2&nbsp; <br />
            网通 S山西 202.99.192.66, 202.99.192.68&nbsp; <br />
            网通 T天津 202.99.96.68, 202.99.104.68&nbsp; <br />
            网通 Z浙江 221.12.1.228, 221.12.33.228, 221.12.65.228, 218.108.248.200&nbsp; <br />
            网通&nbsp; 重庆的DNS 221.5.203.98&nbsp; 221.5.203.99 <br />
            </div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/sword/aggbug/284994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sword/" target="_blank">sw0rd</a> 2009-07-01 17:56 <a href="http://www.blogjava.net/sword/archive/2009/07/01/284994.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate之Criteria 基本查询(转)</title><link>http://www.blogjava.net/sword/archive/2009/06/25/284088.html</link><dc:creator>sw0rd</dc:creator><author>sw0rd</author><pubDate>Thu, 25 Jun 2009 03:51:00 GMT</pubDate><guid>http://www.blogjava.net/sword/archive/2009/06/25/284088.html</guid><wfw:comment>http://www.blogjava.net/sword/comments/284088.html</wfw:comment><comments>http://www.blogjava.net/sword/archive/2009/06/25/284088.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sword/comments/commentRss/284088.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sword/services/trackbacks/284088.html</trackback:ping><description><![CDATA[要对资料库管理系统进行操作，最基本的就是使用SQL（Standard Query Language）语句，大部份的资料库都支援标准的SQL语句，然而也有一些特定于资料库的SQL语句，应用程式配合SQL语句进行资料库查询时，若使用到特定于资料库的SQL语句，程式本身会有相依于特定资料库的问题。<br />
<br />
使用Hibernate时，即使您不了解SQL的使用与撰写，也可以使用它所提供的API来进行SQL语句查询， org.hibernate.Criteria对SQL进行封装，您可以从Java物件的观点来组合各种查询条件，由Hibernate自动为您产生 SQL语句，而不用特别管理SQL与资料库相依的问题，就某个程度的意涵来看，这就像是在编译时期也可以得到对SQL语法的检查与验证。<br />
<br />
以最基本的查询来说，如果您想要查询某个物件所对应的资料表中所有的内容，您可以如下进行查询：<br />
<div style="margin-left: 40px"><font size="3"><small style="font-weight: bold; font-family: Courier New,Courier,monospace">Criteria criteria = session.createCriteria(User.class);</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold; font-family: Courier New,Courier,monospace">List users = criteria.list();</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">for(Iterator it = users.iterator(); it.hasNext(); ) {</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; User user = (User) it.next();</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; System.out.println(user.getId() +</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " \t " + user.getName() +</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "/" + user.getAge());&nbsp;&nbsp;&nbsp; </small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">} </small><br />
</font></div>
<small><br />
<font size="3">Criteria建立后，若不给予任何的条件，预设是查询物件所对应表格之所有资料，如果您执行以上的程式片段，并于设定档中设定了了Hibernate的&#8221;show_sql&#8221;属性，则可以在主控下看到以下的SQL语句之产生：<br />
<br />
</font></small>
<div style="margin-left: 40px"><font size="3"><small><span style="font-family: Courier New,Courier,monospace">Hibernate: </span><span style="font-weight: bold; font-family: Courier New,Courier,monospace">select</span><span style="font-family: Courier New,Courier,monospace"> this_.id as id0_0_, this_.name as name0_0_, this_.age as age0_0_ </span><span style="font-weight: bold; font-family: Courier New,Courier,monospace">from</span><span style="font-family: Courier New,Courier,monospace"> T_USER this_</span></small><br />
</font></div>
<small><br />
</small><small><font size="3">org.hibernate.Criteria实际上是个条件附加的容器，如果想要设定查询条件，则要使用 org.hibernate.criterion.Restrictions的各种静态方法传回 org.hibernate.criterion.Criteria实例，传回的每个org.hibernate.criterion.Criteria 实例代表着一个条件，您要使用org.hibernate.Criteria的add()方法加入这些条件实例，例如查询&#8221; age&#8221;大于20且小于40的资料：<br style="font-weight: bold" />
</font></small>
<div style="margin-left: 40px"><font size="3"><small><span style="font-family: Courier New,Courier,monospace">Criteria criteria = session.createCriteria(User.class);</span></small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold"><span style="font-family: Courier New,Courier,monospace">criteria.add(Restrictions.gt("age", new Integer(20)));</span></small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold"><span style="font-family: Courier New,Courier,monospace">criteria.add(Restrictions.lt("age", new Integer(40)));</span></small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold"><span style="font-family: Courier New,Courier,monospace">List users = criteria.list();</span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">for(Iterator it = users.iterator(); it.hasNext(); ) {</span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; User user = (User) it.next();</span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; System.out.println(user.getId() +</span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " \t " + user.getName() +</span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "/" + user.getAge());&nbsp;&nbsp;&nbsp; </span></small><br style="font-family: Courier New,Courier,monospace" />
<small><span style="font-family: Courier New,Courier,monospace">}</span></small><br style="font-family: Courier New,Courier,monospace" />
</font></div>
<small><br />
<font size="3">Restrictions的gt()方法表示大于（great than）的条件，而lt表示小于（less than）的条件，执行以上程式片段，观察所产生的SQL语句，将使用where与and子句产来完成SQL的条件查询：<br />
<br />
</font></small>
<div style="margin-left: 40px"><font size="3"><small><span style="font-family: Courier New,Courier,monospace">Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_.age as age0_0_ from T_USER this_ </span><span style="font-weight: bold; font-family: Courier New,Courier,monospace">where this_.age&gt;? and this_.age&lt;?</span></small><br />
</font></div>
<small><br />
<font size="3">使用add()方法加入条件时，预设是使用and来组合条件，如果要用or的方式来组合条件，则可以使用Restrictions.or()方法，例如结合age等于（eq）20或（or）age为空（isNull）的条件：<br />
</font></small>
<div style="margin-left: 40px"><font size="3"><small style="font-family: Courier New,Courier,monospace">Criteria criteria = session.createCriteria(User.class);</small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold; font-family: Courier New,Courier,monospace">criteria.add(Restrictions.or(</small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold; font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Restrictions.eq("age", new Integer(20)),</small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold; font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Restrictions.isNull("age")</small><br style="font-weight: bold; font-family: Courier New,Courier,monospace" />
<small style="font-weight: bold; font-family: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ));</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">List users = criteria.list();</small><br />
</font></div>
<small><br />
<font size="3">观察所产生的SQL语句，将使用where与or子句完成SQL的条件查询：<br />
<br />
</font></small>
<div style="margin-left: 40px"><font size="3"><small style="font-family: Courier New,Courier,monospace">Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_.age as age0_0_ from T_USER this_ <span style="font-weight: bold">where (this_.age=? or this_.age is null)</span></small><br />
</font></div>
<small><br />
<font size="3">您也可以使用Restrictions.like()方法来进行SQL中like子句的功能，例如查询&#8221;name&#8221;中名称为&#8221;just&#8221;开头的资料：<br />
</font></small>
<div style="margin-left: 40px"><font size="3"><small style="font-family: Courier New,Courier,monospace">Criteria criteria = session.createCriteria(User.class);</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">criteria.add(<span style="font-weight: bold">Restrictions.like("name", "just%")</span>);</small><br style="font-family: Courier New,Courier,monospace" />
<small style="font-family: Courier New,Courier,monospace">List users = criteria.list();</small><br />
</font></div>
<small><br />
<font size="3">观察所产生的SQL语句如下：<br />
<br />
</font></small>
<div style="margin-left: 40px"><font size="3"><small>Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_.age as age0_0_ from T_USER this_ <span style="font-weight: bold">where this_.name like ?</span></small><br />
</font></div>
<small><br />
<font size="3">Restrictions的几个常用限定查询方法如下表所示：<br />
</font></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small><small></small>
<table style="width: 100%; text-align: left" cellspacing="2" cellpadding="2" border="1">
    <tbody>
        <tr>
            <td style="background-color: rgb(204,204,204)"><small><font size="3">方法</font></small></td>
            <td style="background-color: rgb(204,204,204)"><small><font size="3">说明</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.eq</font></small></td>
            <td><small><font size="3">等于</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.allEq</font></small></td>
            <td><small><font size="3">使用Map，使用key/value进行多个等于的比对</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.gt</font></small></td>
            <td><small><font size="3">大于 &gt;</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.ge</font></small></td>
            <td><small><font size="3">大于等于 &gt;=</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.lt</font></small></td>
            <td><small><font size="3">小于 &lt;</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.le</font></small></td>
            <td><small><font size="3">小于等于 &lt;=</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.between</font></small></td>
            <td><small><font size="3">对应SQL的BETWEEN子句</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.like</font></small></td>
            <td><small><font size="3">对应SQL的LIKE子句</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.in</font></small></td>
            <td><small><font size="3">对应SQL的in子句</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.and</font></small></td>
            <td><small><font size="3">and关系</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.or</font></small></td>
            <td><small><font size="3">or关系</font></small></td>
        </tr>
        <tr>
            <td><small><font size="3">Restrictions.sqlRestriction</font></small></td>
            <td><small><font size="3">SQL限定查询</font></small></td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/sword/aggbug/284088.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sword/" target="_blank">sw0rd</a> 2009-06-25 11:51 <a href="http://www.blogjava.net/sword/archive/2009/06/25/284088.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>