给个分页的例子吧

wangtonglin2009 2011-03-22 11:46:56
最近再弄分页,谁给个分页的例子啊
...全文
157 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiejiangmi 2011-04-06
  • 打赏
  • 举报
回复
写个分页的方法 丢个sql语句 传几个参数就OK了撒
wangtonglin2009 2011-04-05
  • 打赏
  • 举报
回复
build.xml

<?xml version="1.0"?>

<project name="storage" default="deploy" basedir=".">

<property name="projectName" value="storage"></property>
<property name="deployDir" value="E:\tomcat-5.5.28\webapps"></property>
<property name="deployDir" value="D:\tomcat-6.0\webapps"></property>
<property name="srcDir" value="./WebRoot"></property>
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://127.0.0.1:1433;databaseName=storage"></property>
<property name="username" value="sa"></property>
<property name="password" value="1234"></property>

<target name="deploy" description="布署程序到运行目录">
<echo message="${projectName}">
</echo>
<copy todir="${deployDir}/${projectName}">
<fileset dir="${srcDir}">
<include name="**/*.*" />
</fileset>
</copy>
</target>

<target name="clean" description="清空程序运行目录的所有文件">
<delete dir="${deployDir}/${projectName}">
</delete>
</target>

<!--执行Sql,初始化数据-->
<target name="createTables" description="初始化数据库">
<sql driver="${driverClassName}" password="${password}" url="${url}" userid="${username}" delimiter=";" onerror="abort" encoding="UTF-8">
<classpath>
<fileset dir="${basedir}/WebRoot/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</classpath>
<fileset dir="${basedir}/sql">
<include name="storage-create.sql" />
</fileset>
</sql>
</target>
<target name="alterTables" description="添加外键关联" >
<sql driver="${driverClassName}" password="${password}" url="${url}" userid="${username}" delimiter=";" onerror="abort" encoding="UTF-8">
<classpath>
<fileset dir="${basedir}/WebRoot/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</classpath>
<fileset dir="${basedir}/sql">
<include name="storage-alter.sql"/>
</fileset>
</sql>
</target>
<target name="importData" description="从Excel文件导入初始数据" >
<sql driver="${driverClassName}" password="${password}" url="${url}" userid="${username}" delimiter=";" onerror="abort" encoding="UTF-8">
<classpath>
<fileset dir="${basedir}/WebRoot/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</classpath>
<fileset dir="${basedir}/sql">
<include name="storage-importData.sql" />
</fileset>
</sql>
</target>
<target name="initData" description="插入初始数据" >
<sql driver="${driverClassName}" password="${password}" url="${url}" userid="${username}" delimiter=";" onerror="abort" encoding="UTF-8">
<classpath>
<fileset dir="${basedir}/WebRoot/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</classpath>
<fileset dir="${basedir}/sql">
<include name="initData.sql" />
</fileset>
</sql>
</target>
</project>
andylauxing 2011-03-28
  • 打赏
  • 举报
回复
小弟新手,没看明白,不同页面,查询条件不一样,也是说SQL查询语句不同,看了半天,也没见设置这些的方法。
bjvfubj 2011-03-28
  • 打赏
  • 举报
回复
分页多的是
tobywang2009 2011-03-28
  • 打赏
  • 举报
回复

log4j.properties


log4j.rootLogger=INFO, stdout, logfile
log.dir=${storage.root}/log
#print msg to standard consloe
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
#print stdout to file
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${log.dir}/root.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

#define log dir

#define org.springframework log
log4j.category.org.springframework=INFO,A1
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=${log.dir}/spring.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.maxFileSize = 1MB
log4j.appender.A1.maxBackupIndex = 2
log4j.appender.A1.encoding=utf-8
log4j.appender.A1.layout.ConversionPattern=[%d{ISO8601}] %C{3}.%M() %-5p %-x %X{user} %n %m%n

log4j.category.org.hibernate = INFO,A2
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.File=${log.dir}/dao.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.maxFileSize = 1MB
log4j.appender.A2.maxBackupIndex = 2
log4j.appender.A2.encoding=utf-8
log4j.appender.A2.layout.ConversionPattern=[%d{ISO8601}] %C{3}.%M() %-5p %-x %X{user} %n %m%n

#log4j.category.com.sljm.storage.biz = INFO,A3
#log4j.appender.A3=org.apache.log4j.RollingFileAppender
#log4j.appender.A3.File=${log.dir}/security.log
#log4j.appender.A3.layout=org.apache.log4j.PatternLayout
#log4j.appender.A3.maxFileSize = 1MB
#log4j.appender.A3.maxBackupIndex = 2
#log4j.appender.A3.encoding=utf-8
#log4j.appender.A3.layout.ConversionPattern=[%d{ISO8601}] %C{3}.%M() %-5p %-x %X{user} %n %m%n

log4j.category.org.apache.struts2 = INFO,A4
log4j.appender.A4=org.apache.log4j.RollingFileAppender
log4j.appender.A4.File=${log.dir}/struts2.log
log4j.appender.A4.layout=org.apache.log4j.PatternLayout
log4j.appender.A4.maxFileSize = 1MB
log4j.appender.A4.maxBackupIndex = 2
log4j.appender.A4.encoding=utf-8
log4j.appender.A4.layout.ConversionPattern=[%d{ISO8601}] %C{3}.%M() %-5p %-x %X{user} %n %m%n
ctime.class


package com.testingonline.utils;

/**
* @author cui
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Date;
import java.util.Calendar;
import java.util.TimeZone;

/**
* @author Administrator
*
*/
public class CTime {

private static final SimpleDateFormat df = new SimpleDateFormat(
"yyyyMMddHHmmss");
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
private static final SimpleDateFormat sdfk = new SimpleDateFormat(
"yyyy-MM-dd");
private static final SimpleDateFormat dfk = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat ff = new SimpleDateFormat(
"yyyy-MM-01");

/**
* 此为得到准确的当前的时间,一般得到当前的时间要用这个
*
* @return
*/
public static synchronized String getCurrentDate() {
String s = "";
Calendar calend;
TimeZone tz = TimeZone.getTimeZone("GMT+8:00");
TimeZone tzm = TimeZone.getDefault();
//System.out.println(tz);
//System.out.println(tzm);
calend = Calendar.getInstance(tz);
int year = calend.get(Calendar.YEAR);
int m = calend.get(Calendar.MONTH) + 1;
int d = calend.get(Calendar.DATE);
int h = calend.get(Calendar.HOUR_OF_DAY);
int mm = calend.get(Calendar.MINUTE);
int ss = calend.get(Calendar.SECOND);

return CTime.formatWholeDate(calend.getTime());
}

/**
* 返回长日期格式,包含时间 一般用于当前时间取值
*
* @param dt
* Date 型参数
* @return
*/

public static synchronized String formatDate(Date dt) {
if (dt == null) {
return "00000000000000";
}
return df.format(dt);

}

/**
* 返回当前系统时间长日期格式,包含时间 用于取当前时间值
*
* @return
*/
public static String formatDate() {
return df.format(new Date());
}

/**
* 返回长日期格式(带减号),包含时间 ,一般用于当前时间取值
*
* @param dt
* Date 型参数
* @return
*/
public static synchronized String formatWholeDate(Date dt) {
if (dt == null) {
return "0000-00-00 00:00:00.0";
}
return dfk.format(dt);
}

/**
* 返回长日期格式(带减号),包含时间 ,用于当前时间取值
*
* @return
*/
public static String formatWholeDate() {
return dfk.format(new Date());
}

/**
* 返回长日期格式,包含时间 用于对字符串的转换
*
* @param dt
* String 型参数
* @return
*/
public static synchronized String formatDate(String dt) {
StringBuffer strbf = new StringBuffer();
StringTokenizer st = new StringTokenizer(dt.substring(0, 10), "-");
while (st.hasMoreTokens()) {
strbf.append(st.nextToken());
}
st = new StringTokenizer(dt.substring(11, 19), ":");
while (st.hasMoreTokens()) {
strbf.append(st.nextToken());
}
return strbf.toString();
}

/**
* 返回短日期格式,不包含时间 一般用于当前时间取值
*
* @param dt
* Date 型参数
* @return
*/
public static synchronized String formatShortDate(Date dt) {
if (dt == null) {
return "00000000";
}
return sdf.format(dt);
}

/**
* 返回当前系统日期短日期格式,不包含时间 用于取当前日期值<br>
* 格式:20100512
* @return
*/
public static String formatShortDate() {
return sdf.format(new Date());
}

/**
* 返回当前系统日期短日期格式,不包含时间 用于取当前日期值年只取后两位<br>
* 格式:100512 假如当前日期为:2010-05-12
* @return
*/
public static String formatShortYearDate() {
return sdf.format(new Date());
}

/**
* 返回短日期格式(带减号),不包含时间 一般用于当前时间取值
*
* @param dt
* Date 型参数
* @return
*/
public static synchronized String formatRealDate(Date dt) {
if (dt == null) {
return "0000-00-00";
}
return sdfk.format(dt);
}

/**
* 返回短日期格式(带减号),不包含时间 一般用于当前时间取值
*
* @param dt
* Date 型参数
* @return
*/
public static synchronized String formatYearDay(Date dt) {
if (dt == null) {
return "0000-00-00";
}
return ff.format(dt);
}

/**
* 返回短日期格式,不包含时间 用于对字符串的转换
*
* @param dt
* String 型参数
* @return
*/
public static synchronized String formatShortDate(String dt) {
StringBuffer strbf = new StringBuffer();
StringTokenizer st = new StringTokenizer(dt.substring(0, 10), "-");
while (st.hasMoreTokens()) {
strbf.append(st.nextToken());
}

return strbf.toString();
}

/**
* 用于返回中文的方法
*
* @param strvalue
* @return
*/
public static synchronized String toChinese(String strvalue) {
try {
if (strvalue == null) {
return null;
} else {
strvalue = new String(strvalue.getBytes("ISO8859_1"), "GB2312");
return strvalue;
}
} catch (Exception e) {
return null;
}
}

/**
* dateString格式:"YYYY-MM-dd"
* @param dateString
* @return
*/
public static Date parseShortDate(String dateString) {
try {
if (dateString == null)
return new Date();
return dfk.parse(dateString+" 0:0:0");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* dateString格式:"YYYY-MM-dd hh:mm:ss"
* @param dateString
* @return
*/
public static Date parseDate(String dateString) {
try {
if (dateString == null)
return new Date();
return dfk.parse(dateString);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

/**
* 返回上一个时间与现在时间的差
*
* @param last
* @return
*/
public static long cha(String last) {
SimpleDateFormat myFormatter = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
long day = 0L;
java.util.Date date;
try {
date = myFormatter.parse(last);
java.util.Date mydate = myFormatter.parse(CTime.getCurrentDate());
day = (mydate.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);

} catch (ParseException e) {
e.printStackTrace();
}
return day;
}

/**
* 用来产生单号
* @return
*/
public static String getMd(){
SimpleDateFormat myFormatter = new SimpleDateFormat(
"M-d-HHmmss");
String md = myFormatter.format(new Date());
return md;
}

public static String getCurrentShortDate(){
return CTime.formatYearDay(CTime.parseDate(CTime.getCurrentDate()));
}
public static void main(String[] args) {

System.out.println(CTime.parseDate("2010-03-01 0:0:0"));
System.out.println(CTime.getMd());
System.out.println(formatShortDate());
System.out.println(CTime.getCurrentShortDate());
System.out.println(CTime.parseShortDate("2010-03-01"));
System.out.println(CTime.getCurrentDate());
}

}
tobywang2009 2011-03-28
  • 打赏
  • 举报
回复
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>storage.root</param-value>
</context-param>

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/classes/log4j.properties</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- <listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener> -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>


<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>








applicationContext.xml




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<context:annotation-config/>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.testingonline.entity" />
<!--<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
--></bean>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<!-- <property name="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"></property> -->
<property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;DatabaseName=storage"></property>
<!-- <property name="jdbcUrl" value="jdbc:microsoft:sqlserver://192.168.0.15:1433;DatabaseName=storage"></property>-->
<property name="user" value="sa"></property>
<property name="password" value="sa"></property>
<property name="maxPoolSize" value="20"/>
<property name="minPoolSize" value="1"/>
<property name="initialPoolSize" value="1"/>
<property name="maxIdleTime" value="20"/>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- <bean id="logInterceptor" class="woa.security.filter.LogInterceptor"></bean> -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true"/>
<tx:method name="find*" propagation="REQUIRED" read-only="true"/>
<tx:method name="load*" propagation="REQUIRED" read-only="true"/>
<tx:method name="read*" propagation="REQUIRED" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="ServiceOperation"
expression="execution(* com.testingonline.biz.iface.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="ServiceOperation" order="0"/>
<!-- <aop:advisor advice-ref="logInterceptor" pointcut-ref="ServiceOperation" order="1"/> -->
</aop:config>

</beans>


struts.xml



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<constant name="struts.custom.i18n.resources" value="globalMessages"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="devMode" value="true"/>

<package name="storage-default" extends="jasperreports-default">
<interceptors>
<interceptor-stack name="storageStack">
<interceptor-ref name="exception">
<param name="logEnabled">true</param>
<param name="logCategory">com.testingonline.exception.SystemException</param>
<param name="logLevel">ERROR</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>

<default-interceptor-ref name="storageStack"/>
<default-action-ref name="PageNotFoundAction"></default-action-ref>

<global-results>
<result name="accessDeniedException">/accessDenied.jsp</result>
<result name="unhandledException">/error.jsp</result>
</global-results>

<global-exception-mappings>
<exception-mapping exception="org.springframework.security.access.AccessDeniedException" result="accessDeniedException"/>
<exception-mapping exception="com.testingonline.exception.SystemException" result="unhandledException"/>
<exception-mapping exception="java.lang.Exception" result="unhandledException"/>
</global-exception-mappings>
</package>

<include file="struts_config/*.xml" />

</struts>










qq14017152 2011-03-23
  • 打赏
  • 举报
回复
你是要在哪分页啊?是直接在jsp页面分页吗?那就简单了。
e生态_修身 2011-03-23
  • 打赏
  • 举报
回复
看看1楼的不错!!!
songminghong 2011-03-23
  • 打赏
  • 举报
回复
自己上google搜,一大堆的
zn85600301 2011-03-23
  • 打赏
  • 举报
回复
用什么分页都不说 百度里多的是
tobywang2009 2011-03-22
  • 打赏
  • 举报
回复
首先pagebean:
package com.testingonline.utils;

import java.util.ArrayList;
import java.util.List;


public class PageBean<T>{
private int currentPage = 1;
private int totalRows;
private int totalPage;
private int rowsPerPage=10;
private int pageCount=5; //每页显示多少可点的页
private int startPoint; //起始页
private int endPoint; //终止页
private int prePage;
private int nextPage;
private int lastPage;
private int beginIndex; // 起始点 //


private List<T> records=new ArrayList<T>(); // 封装页面显示的数据
private List<Integer> list=new ArrayList<Integer>(); //封装页数的容器,方面客户端迭代

public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRecords) {
this.totalRows = totalRecords;
}

public int getTotalPage() {
if(totalRows%rowsPerPage==0)
this.totalPage=totalRows/rowsPerPage;
else
this.totalPage=totalRows/rowsPerPage+1;
return totalPage;
}

public void setRowsPerPage(int rowsPerPage){
this.rowsPerPage=rowsPerPage;
}

public int getRowsPerPage() {
return rowsPerPage;

}

public int getPrePage() {
if(currentPage-1>0)
this.prePage=currentPage-1;
else
this.prePage=0;
return prePage;
}

public int getNextPage() {
if(currentPage+1<totalPage)
this.nextPage=currentPage+1;
else
this.nextPage=totalPage;
return nextPage;
}

public void setLastPage(int lastPage) {
this.lastPage = lastPage;
}
public int getLastPage() {
lastPage=this.totalPage;
return lastPage;
}

public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public int getBeginIndex() {
this.beginIndex = (this.currentPage - 1) * rowsPerPage;
return beginIndex;
}

public List<T> getRecords() {
return records;
}

public void setRecords(List<T> records) {
this.records = records;
}
public void setList(List<Integer> list) {
this.list = list;
}
public List<Integer> getList() {
return list;
}
public int getStartPoint() {
startPoint = currentPage-pageCount/2;
if(startPoint<=0)
startPoint = 1;
if(totalPage>pageCount){
if(startPoint>(totalPage-pageCount)) //totalPage减去pageCount所得数字包含了最后要显示的几个
startPoint = totalPage-pageCount+1; //页面,如果startPoint等于totalPage减去pageCount,
} //什么也不必改动,否则,如果startPoint大于totalPage减去
return startPoint; //pageCount,则startPoint应加1
}
public void setStartPoint(int startPoint) {
this.startPoint = startPoint;
}
public int getEndPoint() {
if(totalPage>pageCount)
endPoint = startPoint+pageCount-1; //开始页要包含在显示页面上,因此减去1
else
endPoint = totalPage;
return endPoint;
}
public void setEndPoint(int endPoint) {
this.endPoint = endPoint;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}


}

action

package com.chance.materia.action.basic;

import javax.annotation.Resource;

import com.chance.material.biz.iface.IWorkplanService;
import com.chance.material.entity.TbWorkplan;
import com.chance.material.exception.SystemException;
import com.chance.material.utils.PageBean;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class WorkplanAction extends ActionSupport implements
ModelDriven<TbWorkplan> {

private PageBean<TbWorkplan> page = new PageBean<TbWorkplan>();

private String currentPage = null;
@Resource
private IWorkplanService service;
private TbWorkplan tbWorkplan = new TbWorkplan();

public String execute() throws SystemException {

currentPage = currentPage == null ? "" : getCurrentPage();
if (null != currentPage && !currentPage.equals(""))
page.setCurrentPage(Integer.parseInt(currentPage));

page = service.findAll(page);

return SUCCESS;
}

public String add() throws SystemException {
service.initWorkplantypes();
return "add";
}

public String save() throws SystemException {

service.save(tbWorkplan);
return "save";
}

public String delete() throws SystemException {

service.delete(tbWorkplan.getId());
return "delete";
}

public String edit() throws SystemException {// 编辑
service.initWorkplantypes();
tbWorkplan = service.get(tbWorkplan.getId());
return "edit";
}

public String update() throws SystemException {// 编辑完后,保存信息

service.update(tbWorkplan);
return "update";
}

public PageBean<TbWorkplan> getPage() {
return page;
}

public void setPage(PageBean<TbWorkplan> page) {
this.page = page;
}

public String getCurrentPage() {
return currentPage;
}

public void setCurrentPage(String currentPage) {
this.currentPage = currentPage;
}

public TbWorkplan getTbWorkplan() {
return tbWorkplan;
}

public void setTbWorkplan(TbWorkplan tbWorkplan) {
this.tbWorkplan = tbWorkplan;
}

public TbWorkplan getModel() {
// TODO Auto-generated method stub
return tbWorkplan;
}

}


最后jsp页面




<s:iterator value="page.records" var="dealer">
<tr height=30>



<TD bgColor=#ffffff vAlign=center width=121 align=middle>
<s:property value="#dealer.v2" />
</TD>
<TD bgColor=#ffffff vAlign=center width=80 align=middle>
<s:property value="#dealer.v1" />
</TD>
<TD bgColor=#ffffff vAlign=center width=130 align=middle>
<s:property value="#dealer.tbWorkplantype.desc" />
</TD>

</tr>
</s:iterator>




<table>
<tr>
<td colspan="13">
<s:set var="action"><%=basePath%>workplan.action</s:set>
<s:include value="/common/page.jsp"></s:include>
</td>
</tr>
</table>


page.jsp



<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<p class="list_paper">共有<s:property value="page.totalRows"/>条记录

<s:if test="page.currentPage!=1">
<a href="<s:property value='action'/>?currentPage=1">第一页</a>
<a href="<s:property value='action'/>?currentPage=<s:property value='page.currentPage-1'/>">上一页</a>
</s:if>

<s:subset source="page.list" count="page.pageCount" start="page.startPoint-1">
<s:iterator var="row">
<s:if test="page.currentPage==#row">
<s:property value="#row"/> 
</s:if>
<s:elseif test="page.currentPage!=#row">
<a href="<s:property value='action'/>?currentPage=<s:property value='#row'/>"><s:property value="#row"/></a> 
</s:elseif>
</s:iterator>
</s:subset>



<s:if test="page.currentPage!=page.totalPage">
<a href="<s:property value='action'/>?currentPage=<s:property value='page.nextPage'/>">下一页</a>
<a href="<s:property value='action'/>?currentPage=<s:property value='page.lastPage'/>">最后一页</a>
</s:if>

</p>



81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧