|
官方 http://jsptags.com/tags/navigation/pager/index.jsp先向 demo 页面样式: ######################################################################################## request.getParameter 中参数
'pager.offset'=6 <%@ page session="false" %> <%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %> <%@ page contentType="text/html; charset=gb2312"%> <html> <head> <title>Pager Tag Library Demo</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!-- 参数展现 --> request.getParameter 中参数<br/> <%for(Object otmp : request.getParameterMap().keySet() ){%> <%="'"+otmp.toString()+"'"%>=<%=request.getParameter(otmp.toString())%><br\> <%}%>
<form action="<%= request.getRequestURI() %>" method="get"> <br/> <!-- items=数据总条?? index=分页标明展现格式;"center", "forward" or "half-full". maxPageItems=每页最大展现行数; maxIndexPages=每页最大可选页数; isOffset=数据是否展现; scope=参数作用范围;
-->
<pg:pager items="<%= webPalette.length %>" index="<%= "center" %>" maxPageItems="<%= 3 %>" maxIndexPages="<%= 10 %>" isOffset="<%= true %>" export="offset,currentPageNumber=pageNumber" scope="request">
<br/>分页中标签中隐含属性 'offset'=<%=offset%><br/>
<!-- 分页需要向下传递的参数; 比如组合查询使用参数. 此为get提交;乱码问题特别注意; 如:parameter(google) 参数由本页面传递给下一分页页面; --> <pg:param name="google"/>
<!-- 分页具体表现页面 --> <pg:index> <jsp:include page="/WEB-INF/jsp/texticon.jsp" flush="true"/> </pg:index>
<hr> <table width="90%" cellspacing="4" cellpadding="4"> <%for (int i = offset.intValue(),l = Math.min(i + 10, webPalette.length);i < l; i++){%> <pg:item> <tr><th bgcolor="<%= webPalette[i][0] %>"><font color="<%= webPalette[i][1] %>"><%= i + 1 %></font></th></tr> </pg:item> <%}%> </table> <hr>
<pg:index> <jsp:include page="/WEB-INF/jsp/texticon.jsp" flush="true"/> </pg:index>
</pg:pager> </center> </body> </html>
<%! private static final String BLACK = "#000000", WHITE = "#ffffff"; private static final String[][] webPalette = { { WHITE, BLACK}, {"#cccccc",BLACK}, {"#999999",BLACK}, {"#666666",WHITE}, {"#333333",WHITE}, { BLACK, WHITE}, {"#ffcc00",BLACK}, {"#ff9900",BLACK}, {"#ff6600",BLACK}, {"#ff3300",WHITE}, {"#99cc00",BLACK}, {"#cc9900",BLACK}, {"#ffcc33",BLACK}, {"#ffcc66",BLACK}, {"#ff9966",BLACK}, {"#ff6633",BLACK}, {"#cc3300",WHITE}, {"#cc0033",WHITE}, {"#ccff00",BLACK}, {"#ccff33",BLACK}, {"#333300",WHITE} };
private static final String getParam(ServletRequest request, String name, String defval) { String param = request.getParameter(name); return (param != null ? param : defval); }
private static final int getParam(ServletRequest request, String name, int defval) { String param = request.getParameter(name); int value = defval; if (param != null) { try { value = Integer.parseInt(param); } catch (NumberFormatException ignore) { } } return value; }
%>
<!-- 分页具体表现页面 -->
<%@ page session="false" %> <%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<jsp:useBean id="currentPageNumber" type="java.lang.Integer" scope="request"/>
<font face="fixed">
<!-- 到第一页 --> <pg:first export="firstPageUrl=pageUrl" unless="current"> <a href="<%= firstPageUrl %>"> |< </a> </pg:first>
<!-- 每次后退跳10页 --> <pg:skip export="skipBackPageUrl=pageUrl" pages="<%= -10 %>"> <a href="<%= skipBackPageUrl %>"><<<</a> </pg:skip>
<!-- 每次后退跳 1 页 --> <pg:prev export="prevPageUrl=pageUrl"> <a href="<%= prevPageUrl %>"><<</a> </pg:prev>
<!-- 定位 跳页数 --> <pg:pages><% if (pageNumber == currentPageNumber) { %> <b><%= pageNumber %></b> <% } else { %> <a href="<%= pageUrl %>"><%= pageNumber %></a> <% } %></pg:pages>
<!-- 每次前进跳 1 页 --> <pg:next export="nextPageUrl=pageUrl"> <a href="<%= nextPageUrl %>">>></a> </pg:next>
<!-- 每次后前进10页 --> <pg:skip export="skipForwardPageUrl=pageUrl" pages="<%= 10 %>"> <a href="<%= skipForwardPageUrl %>">>>></a> </pg:skip>
<!-- 到最后页 --> <pg:last export="lastPageUrl=pageUrl" unless="current"> <a href="<%= lastPageUrl %>">>|</a> </pg:last>
</font>
-> http://displaytag.sourceforge.net分页流程描述: 1.组合查询参数得取。 比如时间范围,用户名模糊查询。。这些存入 session->data;name 2.通过持久层得到 ‘数据总条数’‘当前展现页数据’; 3.分页点击;根据session 组合参数,再次向数据库申请书及。 代码: <jsp:root version="1.2" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:display="urn:jsptld:http://displaytag.sf.net"> <jsp:directive.page import="java.util.regex.Pattern" /> <jsp:directive.page import="test.Bean" /> <jsp:directive.page import="java.util.ArrayList" /> <jsp:directive.page import="java.util.List" /> <jsp:directive.page contentType="text/html; charset=UTF-8" /> <jsp:include page="inc/header.jsp" flush="true" />
<jsp:scriptlet> <![CDATA[
Pattern pattern = Pattern.compile("d-[0-9]+-p"); String pageIndexName = null ; for(Object otmp : request.getParameterMap().keySet() ){ if( pattern.matcher(otmp.toString()).find() ){ pageIndexName = otmp.toString(); break; } } int pageSize = 10; //每页显示的条数 int pageIndex = 0 ; if(pageIndexName!=null){ pageIndex = (request.getParameter(pageIndexName)==null)? 0:(Integer.parseInt(request.getParameter(pageIndexName)) - 1); //当前页数 } List list = new ArrayList(); for(int i=0;i<pageSize;i++){ list.add( new Bean(pageIndex*10+i,"liu-"+pageIndex*10+i) ); } request.setAttribute("data",list); session.setAttribute( "resultSize", 100 ); out.print("!"+pageIndexName);
]]></jsp:scriptlet>
<h2>数据分页展现开始</h2> <display:table name="data" pagesize="10" partialList="true" size="sessionScope.resultSize"> <display:column property="id" title="ID"></display:column> <display:column property="name" title="名字"></display:column> </display:table> <jsp:include page="inc/footer.jsp" flush="true" />
</jsp:root>
项目开发:就好像是一个取得真理的一个过程。 在开始“没有人”会知道什么是对的,什么是错的。所谓的客户(中世纪教会的教徒),告诉你月亮是“热胀冷缩”造成的“阴晴圆缺”。 在初期你敢于否定“热胀冷缩”原理?或者说根本就是认为月亮是受“热胀冷缩”原理影响的。 那好,下面我们根据月亮圆缺原理,写个统计温度与月亮亮度报表。
客户自己想要的东西也是一个认知的过程。编码要在开始就要确定是在一个不稳定的环境(即使错了我也能容易修改,这是软件最有价值的地方)。对于这些理解为项目的可变性总结出的一些见解: 1.尽量明确各层使用框架。这样能统一技术,明确编码风格,统一存放,查找地址。这样就能很好的 定位要修改文件的物理地址和 尽量不与个人技术有关 。 2.尽量明确各种动作的命名规范。这样不但能很好的使用 aop ,而且为修改提供了 逻辑地址查找提供便利。 3.减少个人英雄主义。由于某些个人原因,引入与项目不兼容的技术,这是很危险的。只有这为“英雄”能修改的后果很严重。 4.编码中对“可预见性”的代码结构适应,扩展接口预留。月亮缺失可能不是“热胀冷缩”引起的怎么办(当然也是最难做到)这只要编码想到可能就有“可变性”就要有好的相应对策,比如:公司鼓励程序员的为“可变性预留接口”,当然最好也注意下预留接口的 规范 。
参考引用: 主题:使用全功能Tomcat简化调试让classpath参数走开直接用eclipse 调试 : tomcat - > service.xml <Context debug="5" docBase="E:/tomcat/tomcatwebroot" path="/tomcatwebroot" reloadable="true" privileged="true"> </Context>这引入一个java 文件 到你的 工程中 import java.io.File; import java.io.FileFilter; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List;
public class MainClassLoad { //commons-lang-2.0.jar static String TOMCAT_HOME = "D:\\apache\\apache-tomcat-5.5.20\\apache-tomcat-5.5.20";
public static void main(String[] args) throws Exception { System.setProperty("catalina.home", TOMCAT_HOME); final ClassLoader classLoader = getClassLoader(new String[]{ TOMCAT_HOME+"\\common\\lib", TOMCAT_HOME+"\\server\\lib", TOMCAT_HOME+"\\bin" }); Object obj = getObject(classLoader,"org.apache.catalina.startup.Catalina"); Method setConfig = obj.getClass().getMethod("setConfig", new Class[]{String.class}); setConfig.invoke(obj, TOMCAT_HOME + "/conf/server.xml"); Method start = obj.getClass().getMethod("start", new Class[]{}); start.invoke(obj, null); } public static Object getObject(ClassLoader classLoader,String className) throws Exception{ return classLoader.loadClass(className).newInstance(); }
public static ClassLoader getClassLoader(String[] libPath) throws Exception{ List<URL> list = new ArrayList<URL>(); FileFilter fileFilter = new FileFilter() { public boolean accept(File dir) { String name = dir.getName().toLowerCase(); return name.endsWith("jar") || name.endsWith("zip"); } }; for(String stmp : libPath){ for(File ftmp : new File(stmp).listFiles(fileFilter) ){ list.add( new URL("file",null,ftmp.getPath()) ); } } URL[] urls = new URL[list.size()]; // fill the urls array with URLs to library files found in libRoot for(int i = 0; i < list.size(); i++) { urls[i] = new URL("file",null,list.get(i).getPath() ); } ClassLoader classLoader = new URLClassLoader(urls, Thread.currentThread(). getContextClassLoader()); return classLoader ; }
}
代码编辑耗时 40 分钟 ;自己感觉很慢!!
文本文件,我想写个Java程序,读一遍这个 文件,然后打印出来文件中英文字母(a 到 z)出现的次数。不区分大小写。 代码: import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map;
public class LinjiawangMain { public static void main(String[] args) throws Exception { Map<Character, Integer> map = getCountByFileLetters("chars.txt") ; for(char ctmp : map.keySet()){ System.out.println( ctmp+"="+map.get(ctmp) ); } } //统计 文件字符工具方法 public static Map<Character, Integer> getCountByFileLetters(String filePath) throws Exception{ //逻辑 参数定义 int int_A = 'A'; int int_Z = 'Z'; int int_a = 'a'; int int_z = 'z'; //数据收集 map (保持存储顺序 使用 LinkedHashMap ) Map<Character, Integer> map = new LinkedHashMap<Character, Integer>(); //以 ISO-8859-1 字符 读取 .classpath 下的 文件 InputStreamReader read = new InputStreamReader(new FileInputStream( LinjiawangMain.class.getClassLoader().getResource(filePath) .getPath()), "ISO-8859-1"); //临时数据收集 int[] iis = new int[int_z-int_a]; while(read.ready() ){ int itmp = read.read(); // 当 'a'<=itmp<='z' (短路) // 当 'A'<=itmp<='Z' (非短路) 后修改itmp到 'a' 到 'z'范围 if( ( itmp >=int_a && itmp<=int_z ) || ( itmp>=int_A && itmp<=int_Z ) | (itmp=(itmp+(int_a-int_A)))>=int_a ){ iis[itmp-int_a]++ ; } } //由 临时数据收集 转 到正式收集 for(int i=0;i<int_z-int_a;i++){ map.put( (char)(i+int_a),iis[i] ); } //非修改 map return Collections.unmodifiableMap(map) ; } }
文件:aAbbbbCCCCc2345ABdb abc d
那位来开个头吧
正则匹配 html标题
<[hH]([1-9])>.*?</[hH]\1> 数据库查询执行顺序: from->where->group by->聚集函数->having->order by table level(id,name) select count(*) as cu from level where id>1 group by name desc having cu>=1 order by id ; 火狐 xpath 取 document dom 值: id('table8')/tbody/tr[6]/td/@valign 数据库有为空列排放位置: 1. select name, case when name is null then 0 else 1 end as is_null from level order by is_null ; 2.select name from level where name is null union select name from level where name is not null ; 数据库报表表链为空项替换为0table a (id); values - > 1 ,2 ,3 table b (id,num); -> (1,15),(1,5) 查询结果为 要为 1 20 2 0 3 0 select a.id as id, sum( case when b.num is null then 0 else b.num end ) as num from a left join b on a.id=b.id group by id ;
package
uu;
import
java.io.BufferedReader;
import
java.io.File;
import
java.io.FileInputStream;
import
java.io.FileOutputStream;
import
java.io.InputStreamReader;
import
java.io.OutputStreamWriter;
import
java.util.ArrayList;
import
java.util.HashMap;
import
java.util.List;
import
java.util.Map;
import
java.util.regex.Pattern;
public
class
MainExc {
//
数据文本
static
String filePath
=
"
smsservice.data
"
;
//
输出文本
static
String outfile
=
"
outfile.html
"
;
//
输出 文本格式
static
String charset
=
"
GBK
"
;
//
数据逻辑 展现
static
Map
<
Pattern, String
>
map
=
new
HashMap
<
Pattern, String
>
();
static
{ map.put(Pattern.compile(
"
^XZT
"
),
"
sina
"
);
。。。。。 }
//
类型定义
static
Map
<
Pattern, String
>
maptype
=
new
HashMap
<
Pattern, String
>
();
static
{
maptype.put(Pattern.compile(
"
^3P45
"
),
"
客户端
"
); maptype.put(Pattern.compile(
"
^6930
"
),
"
图表
"
);
......
}
//
禁止展现
static
List
<
Pattern
>
listNo
=
new
ArrayList
<
Pattern
>
();
static
{ listNo.add(Pattern.compile(
"
^9588Command$
"
)); listNo.add(Pattern.compile(
"
^5kjsCommand$
"
)); listNo.add(Pattern.compile(
"
^529901001011021$
"
)); listNo.add(Pattern.compile(
"
^529901001011022$
"
)); }
public
static
void
main(String[] args)
throws
Exception {
//
read
InputStreamReader read
=
new
InputStreamReader(
new
FileInputStream(MainExc.
class
.getClassLoader().getResource( filePath).getPath()), charset);
//
writer
if
(MainExc.
class
.getClassLoader().getResource(outfile)
==
null
) {
new
File(MainExc.
class
.getClassLoader().getResource(
"
.
"
).getPath()
+
"
/outfile.html
"
).createNewFile(); } OutputStreamWriter writer
=
new
OutputStreamWriter(
new
FileOutputStream(MainExc.
class
.getClassLoader() .getResource(outfile).getPath()), charset);
//
内存 装载 处
List
<
Map
<
String, String
>>
datas
=
new
ArrayList
<
Map
<
String, String
>>
();
StringBuffer buffer
=
new
StringBuffer(); BufferedReader reader
=
new
BufferedReader(read); String stmp
=
null
; List
<
String
>
colName
=
new
ArrayList
<
String
>
();
//
得到 列名
if
((stmp
=
reader.readLine())
!=
null
&&
!
stmp.trim().equals(
""
)) {
//
split - > Tab
for
(String stmp2 : stmp.split(
"
"
)) { colName.add(stmp2); } }
//
列数据收集
while
((stmp
=
reader.readLine())
!=
null
&&
!
stmp.trim().equals(
""
)) {
Map
<
String, String
>
data
=
new
HashMap
<
String, String
>
(); String[] sdata
=
stmp.split(
"
"
);
for
(
int
i
=
0
; i
<
colName.size(); i
++
) { data.put(colName.get(i), sdata[i]); } datas.add(data); }
//
writer
writer.append(
"
<center><table border>\n
"
); writer.append(
"
<tr>
"
+
"
<td>通道伙伴</td>
"
+
"
<td>指令</td>
"
+
"
<td>长号码</td>
"
+
"
<td>资费</td>
"
+
"
<td>业务类型(图表/客户端)</td>
"
+
"
</tr>\n
"
);
//
通道伙伴 指令 长号码 资费 业务类型(图表?客户端?)
wfor:
for
(Map
<
String, String
>
mtmp : datas) {
for
(Pattern ptmp : listNo) {
if
(ptmp.matcher(mtmp.get(
"
command
"
)).find()) {
continue
wfor; } }
String hzhb
=
""
;
for
(Pattern ptmp : map.keySet()) {
if
(ptmp.matcher(mtmp.get(
"
command
"
)).find()) { hzhb
=
map.get(ptmp); } }
String type
=
""
;
for
(Pattern ptmp : maptype.keySet()) {
if
(ptmp.matcher(mtmp.get(
"
command
"
)).find()) { type
=
maptype.get(ptmp); } }
writer.append(
"
<tr>
"
+
"
<td align='center'>
"
+
hzhb
+
"
</td>
"
+
"
<td align='center'>
"
+
mtmp.get(
"
command
"
)
+
"
</td>
"
+
"
<td align='center'>
"
+
mtmp.get(
"
num
"
)
+
"
</td>
"
+
"
<td align='center'>
"
+
mtmp.get(
"
money
"
)
+
"
</td>
"
+
"
<td align='center'>
"
+
type
+
"
</td>
"
+
"
</tr>\n
"
); } writer.append(
"
</table></center>\n
"
);
//
save
writer.flush(); writer.close(); }
}
一篇非常好的 Hibernate 文章 出自: http://guxing.blog.enorth.com.cn/article/174717.shtml Hibernate最让人头大的就是对集合的加载形式。 书看了N次了,还是没有真正理解Hibernate。所以下午专门做了下测试,对配置文件的意思加深了认识。
假设有两个表,Photos(一) --- picture(多)Photo包含picture集合
结论1: HQL代码 > fetch(配置) > lazy (配置) 结论2: 默认 lazy="true" 结论3: fetch 和 lazy 主要是用来级联查询的, 而 cascade 和 inverse 主要是用来级联插入和修改的 结论4: 如果你是用spring来帮你管理你的session, 并且是自动提交,延迟加载就等于没加载~_~(当然除非你手动重新打开session然后手动Hibernate.initialize(set);然后关闭session. 结论5: cascade主要是简化了在代码中的级联更新和删除。 j结论6:老爸可以有多个孩子,一个孩子不能有多个老爸,而且老爸说的算, 孩子围着老爸转。所以Photos老爸要有权力所以 cascade 这个关键子都是送给老爸的, 也就是级联更新,老爸改姓了,儿子也得跟着改,呵呵。“不然,就没有零花钱咯”。而Picture儿子整体挨骂,但是还是要维护父子之间良好的关系,对老爸百依百顺,所以老爸就说,儿子,“关系,由你来维护(inverse="true") ,不然就不给零花钱。呵。”。 <set name="pictures" inverse="true" cascade="all"> <key> <column name="photosid" not-null="true" /> </key> <one-to-many class="girl.domain.Picture" /> </set> 测试代码:
Photos p = ps.getById(1); Set<Picture> set = p.getPictures(); for(Picture pic : set){ System.out.println(pic.getId()); }
配置文件的一部分: <set name="pictures" inverse="true" cascade="all" > <key> <column name="photosid" not-null="true" /> </key> <one-to-many class="girl.domain.Picture" /> </set>
测试过程会对配置文件不断修改:并且从来不曾手动重新打开session
测试结构:
当配置条件为 lazy=true一句查询 测试代码中没有调用getPicture() 正常 Hibernate:
select photos0_.id as id0_0_, photos0_.userid as userid0_0_,
photos0_.typeid as typeid0_0_, photos0_.name as name0_0_,
photos0_.createtime as createtime0_0_, photos0_.description as
descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_
from super.photos photos0_ where photos0_.id=? lazy=true 一句查询 有getPicture() Hibernate: select photos0_.id as
id0_0_, photos0_.userid as userid0_0_, photos0_.typeid as typeid0_0_,
photos0_.name as name0_0_, photos0_.createtime as createtime0_0_,
photos0_.description as descript6_0_0_, photos0_.faceid as faceid0_0_,
photos0_.uri as uri0_0_ from super.photos photos0_ where photos0_.id=? lazy=true 一句查询 有getPicture() 并且访问了里面的元数Picture 且有异常抛出 Hibernate:
select photos0_.id as id0_0_, photos0_.userid as userid0_0_,
photos0_.typeid as typeid0_0_, photos0_.name as name0_0_,
photos0_.createtime as createtime0_0_, photos0_.description as
descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_
from super.photos photos0_ where photos0_.id=?
lazy="false" 两句查询 肯定没问题,因为全部数据都个查了出来 所以怎么调用都正常 Hibernate:
select photos0_.id as id0_0_, photos0_.userid as userid0_0_,
photos0_.typeid as typeid0_0_, photos0_.name as name0_0_,
photos0_.createtime as createtime0_0_, photos0_.description as
descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_
from super.photos photos0_ where photos0_.id=? Hibernate: select
pictures0_.photosid as photosid1_, pictures0_.id as id1_, pictures0_.id
as id2_0_, pictures0_.photosid as photosid2_0_, pictures0_.name as
name2_0_, pictures0_.clicked as clicked2_0_, pictures0_.uploaddate as
uploaddate2_0_, pictures0_.size as size2_0_, pictures0_.description as
descript7_2_0_, pictures0_.uri as uri2_0_ from super.picture pictures0_
where pictures0_.photosid=?
fetch="join" 一句查询 效果 == lazy="false" 呵呵,哪个效率高,我就不知道了。。。。。。。。。。。 Hibernate:
select photos0_.id as id0_1_, photos0_.userid as userid0_1_,
photos0_.typeid as typeid0_1_, photos0_.name as name0_1_,
photos0_.createtime as createtime0_1_, photos0_.description as
descript6_0_1_, photos0_.faceid as faceid0_1_, photos0_.uri as uri0_1_,
pictures1_.photosid as photosid3_, pictures1_.id as id3_, pictures1_.id
as id2_0_, pictures1_.photosid as photosid2_0_, pictures1_.name as
name2_0_, pictures1_.clicked as clicked2_0_, pictures1_.uploaddate as
uploaddate2_0_, pictures1_.size as size2_0_, pictures1_.description as
descript7_2_0_, pictures1_.uri as uri2_0_ from super.photos photos0_
left outer join super.picture pictures1_ on
photos0_.id=pictures1_.photosid where photos0_.id=?
不加fetch="join"一句查询 没有getPicture() 正常 Hibernate: select
photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid
as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as
createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid
as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where
photos0_.id=? 不加fetch="join" 一句查询 有getPicture() 正常 Hibernate: select
photos0_.id as id0_0_, photos0_.userid as userid0_0_, photos0_.typeid
as typeid0_0_, photos0_.name as name0_0_, photos0_.createtime as
createtime0_0_, photos0_.description as descript6_0_0_, photos0_.faceid
as faceid0_0_, photos0_.uri as uri0_0_ from super.photos photos0_ where
photos0_.id=? 不加fetch="join"一句查询 有getPicture() 并且访问里面的元素Picture的ID 有异常抛出 Hibernate:
select photos0_.id as id0_0_, photos0_.userid as userid0_0_,
photos0_.typeid as typeid0_0_, photos0_.name as name0_0_,
photos0_.createtime as createtime0_0_, photos0_.description as
descript6_0_0_, photos0_.faceid as faceid0_0_, photos0_.uri as uri0_0_
from super.photos photos0_ where photos0_.id=? 来个两兵交战 fetch="join" lazy="true" 呵呵 结果,一句查询, 结构正常 所以就当lazy不存在好了。 看来fetch 是老大。、、、、、、、、、、、、、 Hibernate:
select photos0_.id as id0_1_, photos0_.userid as userid0_1_,
photos0_.typeid as typeid0_1_, photos0_.name as name0_1_,
photos0_.createtime as createtime0_1_, photos0_.description as
descript6_0_1_, photos0_.faceid as faceid0_1_, photos0_.uri as uri0_1_,
pictures1_.photosid as photosid3_, pictures1_.id as id3_, pictures1_.id
as id2_0_, pictures1_.photosid as photosid2_0_, pictures1_.name as
name2_0_, pictures1_.clicked as clicked2_0_, pictures1_.uploaddate as
uploaddate2_0_, pictures1_.size as size2_0_, pictures1_.description as
descript7_2_0_, pictures1_.uri as uri2_0_ from super.photos photos0_
left outer join super.picture pictures1_ on
photos0_.id=pictures1_.photosid where photos0_.id=?
参考引用: 使用说明: lib添加dwr.jar web.xml添加 <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app id="dwr"> <display-name>DWR (Direct Web Remoting)</display-name> <description>A Simple Demo DWR</description>
<servlet> <servlet-name>dwr-invoker</servlet-name> <display-name>DWR Servlet</display-name> <description>Direct Web Remoter Servlet</description> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<!-- This should NEVER be present in live --> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param>
</servlet> <!-- 服务起来后 在地址中直接输入 http://.../dwr 就可以查看对外提供的服务类 --> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
</web-app>
dwr.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd"> <dwr> <allow> <!-- 远程调用类 定义 updateItem,getItem 和 findItems 方法可用 --> <create creator="new" javascript="CatalogDAO"> <param name="class" value="com.ajaxlab.ajax.CatalogDAO" /> <include method="getItem" /> <include method="findItems" /> <include method="updateItem" /> </create> <!-- 数据展现定义格式 (javascriot json 格式) 此定义 id name description 为可见 price 隐藏 E.g -> { description:"中国制造.", id:"产品-", name:"新品-" } --> <convert converter="bean" match="com.ajaxlab.ajax.Item"> <param name="include" value="id,name,description,formatted- Price" /> </convert> </allow> </dwr>
类说明 bean Item: private String id = ""; private String name = ""; private String description = ""; private int price = 0; get();set(); dao public Item getItem(String id) { Item item = new Item("产品-"+id); item.setName("新品-"+id); item.setPrice(100); item.setDescription("中国制造."); return item; }
public List findItems(String expression) { List list = new ArrayList(); Item item1 = new Item("产品-001"); item1.setName("新品-001"); item1.setDescription(expression); item1.setPrice(10); Item item2 = new Item("产品-002"); item2.setName("新品-002"); item2.setDescription(expression); item2.setPrice(15); Item item3 = new Item("产品-003"); item3.setName("新品-003"); item3.setDescription(expression); item3.setPrice(35); list.add(item1); list.add(item2); list.add(item3); return list;
}
/* html input text -> { description:"中国制造.", id:"1", name:"刘凯毅" } return true ; */ public boolean updateItem(Item item ){ if( item!=null && item.getName().equals("刘凯毅") ) return true; return false ; }
js 方法: 在 input 输入->> method( !! )
bean(id,name...) {id:1,name:'liukaiyi'}
当多参数 为 map {dd:'liu',aa:'gg'}
js多参数 class.method( objectEval($("p00").value), objectEval($("p01").value), reply0);展现页: <html> <head> <title>DWR Test</title> <!-- These paths use .. so that they still work behind a path mapping proxy. The fully qualified version is more cut and paste friendly. --> <script type='text/javascript' src='/testDwr/dwr/interface/CatalogDAO.js'></script> <script type='text/javascript' src='/testDwr/dwr/engine.js'></script> <script type='text/javascript' src='/testDwr/dwr/util.js'></script> <script type='text/javascript'> //输入到方法中 参数 格式转换 function objectEval(text){ text = text.replace(/\n/g, ' '); text = text.replace(/\r/g, ' '); if (text.match(/^\s*\{.*\}\s*$/)) { text = '[' + text + '][0]'; } return eval(text); } //本例 alert 展现 var reply = function(data){ alert(dwr.util.toDescriptiveString(data, 2)); }
</script>
</head> <body >
<li> findItems( <input type='text' value='""' id='p00' /> ); <input class='ibutton' type='button' onclick='CatalogDAO.findItems(objectEval($("p00").value), reply);' value='Execute' />
</li> <li> getItem( <input class='itext' type='text' size='10' value='""' id='p10' title='Will be converted to: java.lang.String'/> ); <input class='ibutton' type='button' onclick='CatalogDAO.getItem(objectEval($("p10").value), reply);' value='Execute' title='Calls CatalogDAO.getItem(). View source for details.'/> </li>
<li> updateItem( <input class='itext' type='text' size='10' value='{}' id='p20'/> ); <input class='ibutton' type='button' onclick='CatalogDAO.updateItem(objectEval($("p20").value), reply);' value='Execute' /> </li>
</body></html>
|