struts2+spring+hibernate分页代码[比较多]

 更新时间:2008年09月27日 15:27:36   作者:  
J2EE系统中分页显示,修改dao层,service层,action层,两个分页类文件,代码如下

package com.last999.im.news.web;
import com.last999.im.news.web.PageTool;
public class PageMaker {
public PageMaker(){}
public String makeList(PageTool pageinfo,String url){
int linkNumber=10;
int halfLinkNumber=5;
String pageStyle="<style> .ptbl {border:1px solid #CEDBEF;font-size:12px;padding:0;font-family:Arial;width:auto} .ptbl a {text-decoration:none;color:#555555} .ptbl td {padding-top:0px;padding-bottom:0px;padding-left:4px;padding-right:4px} .strong {background:#CEDBEF;font-weight:800;color:#FF7D00} .strong a{color:#FF7D00} .page_input {background:#ffffff;border:1px solid #CEDBEF;border-top:none;border-bottom:none;color:#FF7D00;width:30px;margin:0px } </style>";
String pageTable="<table border='0'cellpadding='0' cellspacing='0' bgcolor='#CEDBEF' class='ptbl'><tr align='center' bgcolor='#FFFBFF'>";
//a string that will be decretion to show
StringBuffer pagelist=new StringBuffer("");
//get current page.
int curpage=pageinfo.getCur();
int pagenumber=pageinfo.getTotal()/pageinfo.getSize()+1;
//make it's pre,next page
int prepage=curpage-1;
prepage=prepage<=0?1:prepage;
int nextpage=curpage+1;
nextpage=nextpage>=pagenumber?pagenumber:nextpage;
//finger out how many page total
pagelist.append(pageStyle);
pagelist.append(pageTable);
pagelist.append("<td>Record:<font color='red'>"+pageinfo.getTotal()+"</font></td>");
//frist page
//pagelist.append("<td><a href='"+url+"1'>|<</a></td>");
//pagelist.append("<td><a href='"+url+prepage+"'><</a></td>");
if (pagenumber<=linkNumber){
for(int i=1;i<=pagenumber;i++){
if(i==curpage)
pagelist.append("<td class='strong'>"+i+"</td>");
else
pagelist.append("<td><a href='"+url+i+"'>"+i+"</a></td>");
}
}else{
int begin=curpage-halfLinkNumber;
begin=(begin<=0)?1:begin;
begin=((halfLinkNumber+curpage)>pagenumber) ? (pagenumber-linkNumber+1):begin;
for(int i=begin;i<=linkNumber+begin-1;i++){
if(i==curpage){
pagelist.append("<td class='strong'>"+i+"</td>");
pagelist.append("\n");
}
else{
pagelist.append("<td><a href='<s:url action='"+url+"'><s:param name='ppp' value='"+i+"'/></s:url>'>"+i+"</a></td>");
pagelist.append("\n");
}
}
}
//pagelist.append("<td><a href='"+url+nextpage+"'>></a></td>");
//pagelist.append("<td><a href='"+url+pagenumber+"'>>|</a></td>");
pagelist.append("<td>Page:<font color='red'>"+pagenumber+"</font></td></tr></table>");
return pagelist.toString();
}
}






KindEntity.java


Java代码
package com.last999.im.news.entity;
/**
* @hibernate.class
* table="kind"
* dynamic-update="true"
*/
public class KindEntity extends Persistent{
private String title;
private String content;
private String parentId;
private String description;
/**
* @hibernate.property
*/
public String getDescription(){
return this.description;
}
public void setDescription(String description) {
this.description=description;
}
private String em1;
private String em2;
private String em3;
/**
* @hibernate.property
*/
public String getEm3(){
return this.em3;
}
public void setEm3(String em3) {
this.em3=em3;
}
/**
* @hibernate.property
*/
public String getEm2(){
return this.em2;
}
public void setEm2(String em2) {
this.em2=em2;
}
/**
* @hibernate.property
*/
public String getEm1(){
return this.em1;
}
public void setEm1(String em1) {
this.em1=em1;
}
/**
* @hibernate.property
*/
public String getParentId(){
return this.parentId;
}
public void setParentId(String parentId) {
this.parentId=parentId;
}
/**
* @hibernate.property
* @hibernate.column name="content" sql-type="TEXT"
*/
public String getContent(){
return this.content;
}
public void setContent(String content) {
this.content=content;
}
/**
* @hibernate.property
*/
public String getTitle(){
return this.title;
}
public void setTitle(String title) {
this.title=title;
}
}
view plaincopy to clipboardprint?
package com.last999.im.news.entity;
/**
* @hibernate.class
* table="kind"
* dynamic-update="true"
*/
public class KindEntity extends Persistent{
private String title;
private String content;
private String parentId;
private String description;
/**
* @hibernate.property
*/
public String getDescription(){
return this.description;
}
public void setDescription(String description) {
this.description=description;
}
private String em1;
private String em2;
private String em3;
/**
* @hibernate.property
*/
public String getEm3(){
return this.em3;
}
public void setEm3(String em3) {
this.em3=em3;
}
/**
* @hibernate.property
*/
public String getEm2(){
return this.em2;
}
public void setEm2(String em2) {
this.em2=em2;
}
/**
* @hibernate.property
*/
public String getEm1(){
return this.em1;
}
public void setEm1(String em1) {
this.em1=em1;
}
/**
* @hibernate.property
*/
public String getParentId(){
return this.parentId;
}
public void setParentId(String parentId) {
this.parentId=parentId;
}
/**
* @hibernate.property
* @hibernate.column name="content" sql-type="TEXT"
*/
public String getContent(){
return this.content;
}
public void setContent(String content) {
this.content=content;
}
/**
* @hibernate.property
*/
public String getTitle(){
return this.title;
}
public void setTitle(String title) {
this.title=title;
}
}

package com.last999.im.news.entity;
/**
* @hibernate.class
* table="kind"
* dynamic-update="true"
*/
public class KindEntity extends Persistent{
private String title;
private String content;
private String parentId;
private String description;
/**
* @hibernate.property
*/
public String getDescription(){
return this.description;
}
public void setDescription(String description) {
this.description=description;
}
private String em1;
private String em2;
private String em3;
/**
* @hibernate.property
*/
public String getEm3(){
return this.em3;
}
public void setEm3(String em3) {
this.em3=em3;
}
/**
* @hibernate.property
*/
public String getEm2(){
return this.em2;
}
public void setEm2(String em2) {
this.em2=em2;
}
/**
* @hibernate.property
*/
public String getEm1(){
return this.em1;
}
public void setEm1(String em1) {
this.em1=em1;
}
/**
* @hibernate.property
*/
public String getParentId(){
return this.parentId;
}
public void setParentId(String parentId) {
this.parentId=parentId;
}
/**
* @hibernate.property
* @hibernate.column name="content" sql-type="TEXT"
*/
public String getContent(){
return this.content;
}
public void setContent(String content) {
this.content=content;
}
/**
* @hibernate.property
*/
public String getTitle(){
return this.title;
}
public void setTitle(String title) {
this.title=title;
}
}






为什么没有在页面接收的代码:



Html代码
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>
showkind
</title>
</head>
<html>
<body>
<center>
<table border="1">
<tr>
<td>
<table border="0" width="755" bgcolor="#eeeeee">
<tr>
<font size="3">
<b>
These are all the kinds:
</b>
</font>
</tr>
<tr>
<td width="%25">title</td>
<td width="%25">description</td>
<td width="%25">parentId</td>
<td width="25%">Content</td>
</tr>
<s:iterator value="%{kindList}" id="kind">
<tr>
<td>
<s:property value="#kind.title"/>
</td>
<td>
<s:property value="#kind.description"/>
</td>
<td>
<s:property value="#kind.parentId"/>
</td>
<td>
<s:property value="#kind.content"/>
</td>
<!--
<td>
<a href="<s:url action='kindDelete'><s:param name='uuid' value='#kind.uuid'/></s:url>">Delete</a>
</td>
-->
</s:iterator>
</tr>
</table>
</td>
</tr>
</table>
<s:property value="pager" escape="false"/>
</center>
</body>
</html>

相关文章

最新评论