日期:2014-05-16 浏览次数:20880 次
十、写测试类测试Spring和Hibernate是否结合成功,测试方法是否正确
?
?
UserServiceTest .java
package ssh.test; import java.util.LinkedHashMap; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import ssh.model.User; import ssh.service.UserService; import ssh.utils.QueryResult; public class UserServiceTest { //测试获取保存 @Test public void save(){ ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); UserService service = (UserService)ctx.getBean("userService"); User user=new User(); user.setName("uuuuuuuuuuuuuu"); service.save(user); } //测试获取分页 @Test public void getScrollData(){ ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); UserService service = (UserService)ctx.getBean("userService"); LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>(); //定义排序 orderby.put("id", "desc"); QueryResult<User> qr =service.getScrollData(1, 5, "o.id>?", new Object[]{3}, orderby); for (User user : qr.getResultlist()) { System.out.println("id:" + user.getId() + " name:" + user.getName()); } } }
??
?
?
十一、封装分页页面
?
??? 1)封装分页工具条页面
????? 调用方法:
?????? <form action="index" method="post">
?????? <%@ include file="/share/fenye.jsp" %>
?????? </form>
? ?
?
fenye.jsp?
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <%@ include file="/share/taglib.jsp" %> <html> <SCRIPT type="text/javascript"> function topage(page){ var form=document.forms[0]; var currentPage=document.getElementById(currentPage); form.currentPage.value=page; form.submit(); } </SCRIPT> <body> <input type="hidden" name="pageView.currentPage" id="currentPage" value="10"/> 当前页:第${pageView.currentPage} | 总记录数:${pageView.totalRecord} | 每页显示:${pageView.maxResult}|总页数:${pageView.totalPage}| <c:if test="${pageView.currentPage==1}">首页|上一页</c:if> <c:if test="${pageView.currentPage!=1}"><a href="javascript:topage(1)">首页</a>|<a href="javascript:topage('${pageView.currentPage-1}')">上一页</a></c:if>|第 <c:forEach begin="${pageView.startIndex}" end="${pageView.endIndex}" var="i"> <c:if test="${pageView.currentPage==i}"><b>${i }</b></c:if> <c:if test="${pageView.currentPage!=i}"><a href="javascript:topage('${i}')">${i}</a></c:if> </c:forEach>页| <c:if test="${pageView.currentPage==pageView.totalPage}">下一页|末页</c:if> <c:if test="${pageView.currentPage!=pageView.totalPage}"><a href="javascript:topage('${pageView.currentPage+1}')">下一页</a>|<a href="javascript:topage('${pageView.totalPage}')">末页</a></c:if> </body> </html>
??
???
? 2)定义头不集合页面,每个JSP页面直接包含就行<%@ include file="/share/taglib.jsp" %>
?
taglib.jsp