发表于: 2018-03-26 23:34:51
1 512
今天完成的事情:
1.配置jetty插件
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.9.v20130131</version>
<configuration>
<stopPort>9988</stopPort>
<stopKey>foo</stopKey>
<scanIntervalSeconds>5</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8014</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
</configuration>
</plugin>
2.实现数据的分页
使用的一个pageBean.java的类获取当前页面需要显示的对象集合。
public class PageBean<T> {
private int currPage;
private int pageSize;
private int totalCount;
private int totalPage;
private List<Student> lists;
在studentServiceImpl中拿到分页查询的集合。需要使用的sql语句是“select * from t_students limit #{start},#{size}”在数据库中直接拿到分页查询的集合。
public PageBean<Student> findByPage(int currentPage) throws Exception{
HashMap<String,Object> map=new HashMap<String, Object>();
PageBean<Student> pageBean=new PageBean<Student>();
//封装当前页数
pageBean.setCurrPage(currentPage);
//每页显示的数据数
int pageSize=6;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount =studentDao.selectCount();
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
//必须时Double,如果是double则intValue()报红色
Double num= Math.ceil(tc/pageSize);
pageBean.setTotalPage(num.intValue());
map.put("start",(currentPage-1)*pageSize);
map.put("size",pageBean.getPageSize());
//封装每页显示的数据
List<Student> lists=studentDao.findByPage(map);
pageBean.setLists(lists);
return pageBean;
}
JSP页面中转换页面的按钮
<table border="0" cellspacing="0" cellpadding="0" width="900px">
<tr>
<td class="td2">
<span>第${requestScope.pagemsg.currPage }/ ${requestScope.pagemsg.totalPage}页</span>
<span>总记录数:${requestScope.pagemsg.totalCount } 每页显示:${requestScope.pagemsg.pageSize}</span>
<span>
<c:if test="${requestScope.pagemsg.currPage != 1}">
<a href="${pageContext.request.contextPath }/haha/main?currentPage=1">[首页]</a>
<a href="${pageContext.request.contextPath }/haha/main?currentPage=${requestScope.pagemsg.currPage-1}">[上一页]</a>
</c:if>
<c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
<a href="${pageContext.request.contextPath }/haha/main?currentPage=${requestScope.pagemsg.currPage+1}">[下一页]</a>
<a href="${pageContext.request.contextPath }/haha/main?currentPage=${requestScope.pagemsg.totalPage}">[尾页]</a>
</c:if>
</span>
</td>
</tr>
</table>
明天的计划:
整理一下做的CURD、页面转换和分页。
遇到的问题:
1.RESTful 的风格还没有掌握,明天再找资料看下。
收获:
完成更新和删除,页面转换和分页查询(mysql的命令形式)。
评论