
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
- version="4.0">
-
- <!--配置中央控制器-->
- <servlet>
- <servlet-name>ActionServlet</servlet-name>
- <servlet-class>com.zking.mvc.framework.ActionServlet</servlet-class>
- <!--设置config配置文件-->
- <init-param>
- <param-name>config</param-name>
- <param-value>/config.xml</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>ActionServlet</servlet-name>
- <url-pattern>*.action</url-pattern>
- </servlet-mapping>
- <!--配置中文过滤器-->
- <filter>
- <filter-name>EncodingFilter</filter-name>
- <filter-class>com.jmh.utils.EncodingFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>EncodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
- <!DOCTYPE taglib
- PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
- "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
- <!-- 标签库描述符 -->
- <taglib xmlns="http://java.sun.com/JSP/TagLibraryDescriptor">
- <tlib-version>1.0</tlib-version>
- <jsp-version>1.2</jsp-version>
- <short-name>Simple Tags</short-name>
- <uri>/zking</uri>
- <tag>
- <name>page</name>
- <tag-class>com.jmh.utils.PageTag</tag-class>
- <body-content>empty</body-content>
- <attribute>
- <name>pageBean</name>
- <required>true</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
- </taglib>
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- 根目录 -->
- <config>
- <!-- 第一个action标签 -->
- <!--indexAction-->
- <action path="/indexAction" type="com.jmh.action.IndexAction">
- <forward name="failed" path="/add.jsp" redirect="false" />
- <forward name="success" path="/add.jsp" redirect="true" />
- </action>
- <!--userAction-->
- <action path="/userAction" type="com.jmh.action.UserAction">
- <forward name="failed" path="/add.jsp" redirect="false" />
- <forward name="success" path="/add.jsp" redirect="true" />
- </action>
- <!--bookAction-->
- <action path="/bookAction" type="com.jmh.action.BookAction">
- <!--跳转主页使用转发(查询全部、模糊查询)-->
- <forward name="list" path="/listBook.jsp" redirect="false" />
- <!--跳转查询全部功能使用重定向(删除)-->
- <forward name="success" path="/bookAction.action?methodName=listBook" redirect="true" />
- <!--跳转查看单个页面使用转发(查看单个)-->
- <forward name="load" path="/loadBook.jsp" redirect="false" />
- <!--跳转查看编辑页面使用转发(编辑书本信息)-->
- <forward name="edit" path="/editBook.jsp" redirect="false" />
- <!--跳转绑定数据的功能(编辑书本成功之后)-->
- <forward name="update" path="/bookAction.action?methodName=listBook" redirect="true" />
- </action>
- </config>
- package com.jmh.entity;
-
- import java.io.Serializable;
-
- /**
- * 书本对象
- */
- public class Book implements Serializable {
- private Integer book_id;//书本编号
- private String book_name;//书本名称
- private float price;//书本价格
-
- public Book(Integer book_id, String book_name, float price) {
- this.book_id = book_id;
- this.book_name = book_name;
- this.price = price;
- }
-
- public Book() {
- }
-
- public Integer getBook_id() {
- return book_id;
- }
-
- public String getBook_name() {
- return book_name;
- }
-
- public float getPrice() {
- return price;
- }
-
- public void setBook_id(Integer book_id) {
- this.book_id = book_id;
- }
-
- public void setBook_name(String book_name) {
- this.book_name = book_name;
- }
-
- public void setPrice(float price) {
- this.price = price;
- }
-
- @Override
- public String toString() {
- return "Book{" +
- "book_id=" + book_id +
- ", book_name='" + book_name + '\'' +
- ", price=" + price +
- '}';
- }
- }
- package com.jmh.dao;
-
- import com.jmh.base.BaseDao;
- import com.jmh.entity.Book;
- import com.jmh.utils.CommonUtils;
- import com.jmh.utils.PageBean;
- import com.jmh.utils.StringUtils;
-
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.List;
-
- public class BookDao extends BaseDao<Book> {
- /**
- * 分页查询的方法
- * @param b 书本对象
- * @param pb 工具类
- * @return 结果集合
- */
- public List<Book> listBook(Book b, PageBean pb){
- //普通查询语句
- String sql="select book_id,book_name,price from tb_book where 1=1";
- //符合模糊查询语句
- if(StringUtils.isNotBlank(b.getBook_name())){//书本名称不等于空
- sql+=" and book_name like '%"+b.getBook_name()+"%' ";
- }
- //返回===调用父类的查询方法
- return this.executeQuery(sql, pb, new CallBack() {
- @Override
- public List forEachRs(ResultSet rs) throws SQLException {
- return CommonUtils.toList(rs,Book.class);
- }
- });
- }
-
- /**
- * 新增书本方法
- * @param b 书本对象
- */
- public void insertBook(Book b){
- //编写增加书本的sql语句
- String sql="insert into tb_book " +
- "(book_name,price) values(?,?)";
- this.executeUpdate(sql,new Object[]{
- b.getBook_name(),
- b.getPrice()
- });
- }
-
- /**
- * 根据书本编号删除的方法
- * @param b 书本对象
- */
- public void deleteBook(Book b){
- //编写根据书本编号删除的sql语句
- String sql="delete from tb_book where book_id=?";
- this.executeUpdate(sql,new Object[]{
- b.getBook_id()
- });
- }
-
- /**
- * 根据书本编号编辑书本
- * @param b 书本编号
- */
- public void updateBook(Book b){
- //编写根据书本编号编辑书本的sql语句
- String sql="update tb_book set book_name=?,price=? where book_id=?";
- this.executeUpdate(sql,new Object[]{
- b.getBook_name(),
- b.getPrice(),
- b.getBook_id()
- });
- }
-
- /**
- * 根据书本编号查询书本单个信息
- * @param b 书本信息
- * @return 书本单个信息
- */
- public Book loadBook(Book b){
- //编写根据书本编号查询书本信息的sql语句
- String sql="select book_id,book_name,price from tb_book where book_id="+b.getBook_id();
- List<Book> listBook= this.executeQuery(sql, null, new CallBack() {
- @Override
- public List forEachRs(ResultSet rs) throws SQLException {
- return CommonUtils.toList(rs,Book.class);
- }
- });
- return listBook.get(0);
- }
-
- }
- package com.jmh.base;
-
- import java.sql.*;
- import java.util.List;
-
- import com.jmh.entity.Book;
- import com.jmh.utils.DBHelper;
- import com.jmh.utils.PageBean;
- import com.jmh.utils.StringUtils;
-
- public class BaseDao<K> {
- /**
- * 回调函数 用于遍历rs结果集
- * @author Administrator
- *
- * @param <T>
- */
- public static interface CallBack<T> {
- public List<T> forEachRs(ResultSet rs) throws SQLException;
- }
-
- //带有分页的模糊查询方法
- public List<K> executeQuery(String sql,PageBean pageBean,CallBack callBack){
- Connection conn = null;
- PreparedStatement pst = null;
- ResultSet rs = null;
- try {
- conn = DBHelper.getConnection();
- //查询总记录数
- if(null!=pageBean && pageBean.isPagination()) {
- String countSql = this.getCountSql(sql);
- pst = conn.prepareStatement(countSql);
- rs = pst.executeQuery();
- if(rs.next()) {
- Object obj = rs.getInt(1);
- pageBean.setTotal(obj.toString());
- }
- DBHelper.close(null, pst, rs);
- }
- if(null!=pageBean && pageBean.isPagination()) {
- sql = this.getPageSql(sql,pageBean);
- }
-
- pst = conn.prepareStatement(sql);
- rs = pst.executeQuery();
-
-
- return callBack.forEachRs(rs);
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }finally {
- DBHelper.close(conn, pst, rs);
- }
-
-
-
-
- }
- /**
- * 得到总记录数的sql
- * @param sql
- * @return
- */
- private String getCountSql(String sql) {
- String countSql = "SELECT COUNT(*) FROM ("+sql+") t1";
- return countSql;
- }
-
- /**
- * 得到分页的sql
- * @param sql
- * @param pageBean
- * @return
- */
- private String getPageSql(String sql,PageBean pageBean) {
- String pageSql = sql + " LIMIT "+pageBean.getStartIndex()+","+pageBean.getRows();
- return pageSql;
-
-
- }
-
- /**
- * 方便增删改的方法
- * @param sql
- * @param params
- */
- public void executeUpdate(String sql,Object[] params) {
- Connection conn=null;
- PreparedStatement stmt=null;
- try {
- conn=DBHelper.getConnection();
- stmt=conn.prepareStatement(sql);
- ParameterMetaData metaData = stmt.getParameterMetaData();
- for (int i = 0; i < metaData.getParameterCount(); i++) {
- stmt.setObject(i+1, params[i]);
- }
- int i = stmt.executeUpdate();
- if(i<1)
- throw new RuntimeException("执行失败,影响行数为0!");
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } finally {
- DBHelper.close(conn, stmt, null);
- }
- }
-
- }
- #mysql
- driver=com.mysql.jdbc.Driver
- url=jdbc:mysql://localhost:3306/填写自己的数据库名称?useUnicode=true&characterEncoding=UTF-8
- user=填写自己的数据库登录账号
- pwd=填写自己的数据库登录密码
- package com.jmh.utils;
-
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
-
- /**
- * 提供了一组获得或关闭数据库对象的方法
- *
- */
- public class DBHelper {
- private static String driver;
- private static String url;
- private static String user;
- private static String password;
-
- static {// 静态块执行一次,加载 驱动一次
- try {
- InputStream is = DBHelper.class
- .getResourceAsStream("config.properties");
-
- Properties properties = new Properties();
- properties.load(is);
-
- driver = properties.getProperty("driver");
- url = properties.getProperty("url");
- user = properties.getProperty("user");
- password = properties.getProperty("pwd");
-
- Class.forName(driver);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- /**
- * 获得数据连接对象
- *
- * @return
- */
- public static Connection getConnection() {
- try {
- Connection conn = DriverManager.getConnection(url, user, password);
- return conn;
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public static void close(ResultSet rs) {
- if (null != rs) {
- try {
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- }
-
- public static void close(Statement stmt) {
- if (null != stmt) {
- try {
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- }
-
- public static void close(Connection conn) {
- if (null != conn) {
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
- }
-
- public static void close(Connection conn, Statement stmt, ResultSet rs) {
- close(rs);
- close(stmt);
- close(conn);
- }
-
- public static boolean isOracle() {
- return "oracle.jdbc.driver.OracleDriver".equals(driver);
- }
-
- public static boolean isSQLServer() {
- return "com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(driver);
- }
-
- public static boolean isMysql() {
- return "com.mysql.jdbc.Driver".equals(driver);
- }
-
- public static void main(String[] args) {
- Connection conn = DBHelper.getConnection();
- DBHelper.close(conn);
- System.out.println("isOracle:" + isOracle());
- System.out.println("isSQLServer:" + isSQLServer());
- System.out.println("isMysql:" + isMysql());
- System.out.println("数据库连接(关闭)成功");
- }
- }
- package com.jmh.utils;
-
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.servlet.http.HttpServletResponse;
-
-
-
- public class CommonUtils {
-
-
-
- /**
- * 根据ResultSet数据集,利用反射机制动态赋值并返回List<T>
- * @param rs ResultSet数据集
- * @param clazz 实体类对象
- * @return 返回List实体集合
- * @throws Exception
- */
- public static <T> List<T> toList(ResultSet rs,Class<T> clazz){
- //定义实体集合
- List<T> lst=new ArrayList<T>();
- try {
- //获取ResultSet的metadata列信息
- ResultSetMetaData metaData = rs.getMetaData();
- //获取对象属性集合
- Field[] fields=clazz.getDeclaredFields();
- //循环ResultSet
- while(rs.next()) {
- //反射机制实例化
- T obj = clazz.newInstance();
- for (int i = 0; i < metaData.getColumnCount(); i++) {
- //获取列名
- String columnName=metaData.getColumnLabel(i+1).toUpperCase();
- for (Field field : fields) {
- //判断属性名与列名是否相同
- if(field.getName().toUpperCase().equals(columnName)) {
- //获取属性对应的set方法名,方法名首字母大写
- String methodName="set"+field.getName().substring(0, 1).toUpperCase()+field.getName().substring(1);
- //获取属性对应的set方法
- Method method = obj.getClass().getDeclaredMethod(methodName, field.getType());
- //设置访问权限
- method.setAccessible(true);
- //执行set方法,将数据存储到对象中的相应属性中
- method.invoke(obj, rs.getObject(columnName));
- break;
- }
- }
- }
- lst.add(obj);
- }
- }catch(Exception e) {
- e.printStackTrace();
- }
- return lst;
- }
-
- /**
- * 多表查询时返回结果集,利用反射机制赋值
- * @param rs
- * @return 返回List<Map<String,Object>>
- * @throws Exception
- */
- public static List<Map<String,Object>> toList(ResultSet rs){
- //定义实体集合
- List<Map<String,Object>> lst=new ArrayList<Map<String,Object>>();
- try {
- //获取ResultSet的metadata列信息
- ResultSetMetaData metaData = rs.getMetaData();
- Map<String,Object> set=null;
- while(rs.next()) {
- set=new HashMap<String,Object>();
- for (int i = 0; i < metaData.getColumnCount(); i++) {
- String columnName=metaData.getColumnLabel(i+1);
- set.put(columnName, rs.getObject(columnName));
- }
- lst.add(set);
- }
- }catch(Exception e) {
- e.printStackTrace();
- }
- return lst;
- }
- }
- package com.jmh.utils;
-
- import java.io.IOException;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
-
- import javax.servlet.Filter;
- import javax.servlet.FilterChain;
- import javax.servlet.FilterConfig;
- import javax.servlet.ServletException;
- import javax.servlet.ServletRequest;
- import javax.servlet.ServletResponse;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- /**
- * 中文乱码处理
- *
- */
- public class EncodingFilter implements Filter {
-
- private String encoding = "UTF-8";// 默认字符集
-
- public EncodingFilter() {
- super();
- }
-
- public void destroy() {
- }
-
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- HttpServletRequest req = (HttpServletRequest) request;
- HttpServletResponse res = (HttpServletResponse) response;
-
- // 中文处理必须放到 chain.doFilter(request, response)方法前面
- res.setContentType("text/html;charset=" + this.encoding);
- if (req.getMethod().equalsIgnoreCase("post")) {
- req.setCharacterEncoding(this.encoding);
- } else {
- Map map = req.getParameterMap();// 保存所有参数名=参数值(数组)的Map集合
- Set set = map.keySet();// 取出所有参数名
- Iterator it = set.iterator();
- while (it.hasNext()) {
- String name = (String) it.next();
- String[] values = (String[]) map.get(name);// 取出参数值[注:参数值为一个数组]
- for (int i = 0; i < values.length; i++) {
- values[i] = new String(values[i].getBytes("ISO-8859-1"),
- this.encoding);
- }
- }
- }
-
- chain.doFilter(request, response);
- }
-
- public void init(FilterConfig filterConfig) throws ServletException {
- String s = filterConfig.getInitParameter("encoding");// 读取web.xml文件中配置的字符集
- if (null != s && !s.trim().equals("")) {
- this.encoding = s.trim();
- }
- }
-
- }
- package com.jmh.utils;
-
- import java.util.Map;
-
- import javax.servlet.http.HttpServletRequest;
-
- public class PageBean {
-
- private Integer page =1; //页码 默认为1
-
- private Integer rows = 10; //页大小 默认为10
-
- private Integer total =0; // 总记录数
-
- private boolean pagination=true; //是否分页 默认为false
-
-
- private String url; //请求路径
-
-
- private Map<String,String[]> map; //请求的参数集合
-
- public PageBean() {
- super();
- }
-
- public Integer getPage() {
- return page;
- }
-
- public void setPage(Integer page) {
- this.page = page;
- }
-
- public Integer getRows() {
- return rows;
- }
-
- public void setRows(Integer rows) {
- this.rows = rows;
- }
-
- public Integer getTotal() {
- return total;
- }
-
- public void setTotal(Integer total) {
- this.total = total;
- }
-
- public void setTotal(String total) {
- this.total = Integer.parseInt(total);
- }
-
- public boolean isPagination() {
- return pagination;
- }
-
- public void setPagination(boolean pagination) {
- this.pagination = pagination;
- }
-
- // @Override
- // public String toString() {
- // return "PageBean [page=" + page + ", rows=" + rows + ", total=" + total + ", pagination=" + pagination + "]";
- // }
-
- public int getStartIndex() {
- return (this.page-1)*this.rows;
-
-
- }
-
-
- @Override
- public String toString() {
- return "PageBean [page=" + page + ", rows=" + rows + ", total=" + total + ", pagination=" + pagination
- + ", url=" + url + ", map=" + map + "]";
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public Map<String, String[]> getMap() {
- return map;
- }
-
- public void setMap(Map<String, String[]> map) {
- this.map = map;
- }
-
-
- public void setPage(String page) {
- if(null!=page && !"".equals(page)) {
- this.page = Integer.parseInt(page);
- }
- }
-
- public void setRows(String rows) {
- if(null!=rows && !"".equals(rows)) {
- this.rows = Integer.parseInt(rows);
- }
- }
-
-
-
- public void setPagination(String pagination) {
- if(null!=pagination && !"".equals(pagination)) {
- this.pagination = Boolean.parseBoolean(pagination);
- }
- }
- /**
- * 对pageBean初始化
- * @param req
- */
- public void setRequest(HttpServletRequest req) {
-
- //获取页面上的参数
- String page = req.getParameter("page");
- String rows = req.getParameter("rows");
- String pagination = req.getParameter("pagination");
-
- //设置参数
-
- this.setPage(page);
- this.setRows(rows);
- this.setPagination(pagination);
-
- this.setUrl(req.getRequestURI());
- this.setMap(req.getParameterMap());
-
- }
-
- /**
- * 得到最大的页码数
- * @return
- */
- public int getMaxPage() {
- int maxPage = this.total / this.rows;
- if(this.total%this.rows!=0) {
- maxPage++;
- }
- return maxPage;
- }
-
- /**
- * 得到下一页的页码
- * @return
- */
- public int getNextPage() {
- int nextPage = this.page+1;
- if(nextPage>=getMaxPage()) {
- nextPage = getMaxPage();
- }
- return nextPage;
- }
-
- /**
- * 得到上一页的页码
- * @return
- */
- public int getPreviousPage() {
- int previousPage = this.page -1;
- if(previousPage<1) {
- previousPage =1;
- }
- return previousPage;
- }
-
- }
- package com.jmh.utils;
-
- import java.io.IOException;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Set;
-
- import javax.servlet.jsp.JspException;
- import javax.servlet.jsp.JspWriter;
- import javax.servlet.jsp.tagext.BodyTagSupport;
-
- import com.jmh.utils.PageBean;
-
-
-
- public class PageTag extends BodyTagSupport {
- private PageBean pageBean;
-
- public PageTag() {
- super();
- }
-
- public PageBean getPageBean() {
- return pageBean;
- }
-
- public void setPageBean(PageBean pageBean) {
- this.pageBean = pageBean;
- }
-
- @Override
- public int doStartTag() throws JspException {
- JspWriter out = pageContext.getOut();
- try {
- out.println(toHtml());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return super.doStartTag();
- }
-
-
- private String toHtml() {
- //pageBean为空或者 不分页
- if(null==pageBean || !pageBean.isPagination()) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- //拼接form表单
- /*<form action="${pageBean.url}" method="post" id="pageBeanForm">
- <!-- 设置页码 -->
- <input type="hidden" name="page"/>
- <!-- 参数列表 -->
- </form>*/
- sb.append("<form action=\""+pageBean.getUrl()+"\" method=\"post\" id=\"pageBeanForm\">");
- sb.append("<input type=\"hidden\" name=\"page\"/>");
-
- //参数列表
-
- Map<String, String[]> map = pageBean.getMap();
- String name =null;
- String[] values = null;
- // bookName = '不短命' hobby="篮球" hobby="足球" page="2"
- Set<Entry<String, String[]>> entrySet = map.entrySet();
- for (Entry<String, String[]> entry : entrySet) {
- name = entry.getKey();
- if(name.equals("page")) {
- continue;
- }
- values = entry.getValue();
- for (String value : values) {
-
- //<input type="hidden" name="bookName" valu="不短命"/>
- //<input type="hidden" name="hobby" valu="篮球"/>
- //<input type="hidden" name="hobby" valu="足球"/>
- sb.append("<input type=\"hidden\" name=\""+name+"\" value=\""+value+"\"/>");
- }
- }
- sb.append("</form>");
-
-
- //拼接div部分
- /*<div style="width:100%;text-align: right;">
- 第几页/总共多少页,共多少条记录
- <a href="javascript:gotoPage(1)">首页</a>
- <a href="javascript:gotoPage(${pageBean.getPreviousPage()})">上一页</a>
- <a href="javascript:gotoPage(${pageBean.getNextPage()})">下一页</a>
- <a href="javascript:gotoPage(${pageBean.getMaxPage()})">末页</a>
- <input type="text" id="skipPage" style="width:30px;"/>
- <a href="javascript:skipPage(${pageBean.getMaxPage()})">GO</a>
-
-
-
- </div>*/
- sb.append("<div style=\"width:100%;text-align: right;\">");
- sb.append("第"+pageBean.getPage()+"页/总共"+pageBean.getMaxPage()+"页,共"+pageBean.getTotal()+"条记录 ");
-
- //首页 上一页
- if(pageBean.getPage()!=1) {
- sb.append("<a href=\"javascript:gotoPage(1)\">首页</a> \r\n" +
- " <a href=\"javascript:gotoPage("+pageBean.getPreviousPage()+")\">上一页</a> ");
- }else {
- sb.append("<a>首页</a> <a>上一页</a> ");
- }
-
-
- //末页 下一页
-
- if(pageBean.getPage()!=pageBean.getMaxPage()) {
- sb.append("<a href=\"javascript:gotoPage("+pageBean.getNextPage()+")\">下一页</a> \r\n" +
- " <a href=\"javascript:gotoPage("+pageBean.getMaxPage()+")\">末页</a> ");
- }else {
- sb.append("<a>下一页</a> <a>末页</a> ");
- }
-
- //跳转页
- sb.append("<input type=\"text\" id=\"skipPage\" style=\"width:30px;\"/> ");
- sb.append("<a href=\"javascript:skipPage()\">GO</a>");
- sb.append("</div>");
-
- //拼接js
- /*<script type="text/javascript">
- function gotoPage(page) {
- document.getElementById('pageBeanForm').page.value=page;
- document.getElementById('pageBeanForm').submit();
- }
- function skipPage(maxPage) {
- var page = document.getElementById('skipPage').value;
- if(isNaN(page) || page<1 || page>maxPage){
- alert("请输入1-"+maxPage+"的数字");
- return false;
- }
- gotoPage(page);
- }
- </script>*/
-
- sb.append("<script type=\"text/javascript\">\r\n" +
- " function gotoPage(page) {\r\n" +
- " document.getElementById('pageBeanForm').page.value=page;\r\n" +
- " document.getElementById('pageBeanForm').submit();\r\n" +
- " }\r\n" +
- " function skipPage() {\r\n" +
- " var page = document.getElementById('skipPage').value;\r\n" +
- " if(isNaN(page) || page<1 || page>"+pageBean.getMaxPage()+"){\r\n" +
- " alert(\"请输入1-\"+"+pageBean.getMaxPage()+"+\"的数字\");\r\n" +
- " return false;\r\n" +
- " }\r\n" +
- " gotoPage(page);\r\n" +
- " }\r\n" +
- "\r\n" +
- "</script>");
-
-
- return sb.toString();
- }
-
-
- }
- package com.jmh.utils;
-
- public class StringUtils {
- // 私有的构造方法,保护此类不能在外部实例化
- private StringUtils() {
- }
-
- /**
- * 如果字符串等于null或去空格后等于"",则返回true,否则返回false
- *
- * @param s
- * @return
- */
- public static boolean isBlank(String s) {
- boolean b = false;
- if (null == s || s.trim().equals("")) {
- b = true;
- }
- return b;
- }
-
- /**
- * 如果字符串不等于null或去空格后不等于"",则返回true,否则返回false
- *
- * @param s
- * @return
- */
- public static boolean isNotBlank(String s) {
- return !isBlank(s);
- }
-
- }
除了还有一些核心代码作者导成了jar方便使用,如有需要私我即可.然后。。。就到这里啦?
效果图如下:
