接下来开发
个人中心
个人中心包括内容:
1、
修改个人信息
2、
列出我提出的问题
3、
列出我回答过的问题
4、
列出被采纳的问题
分页大概的流程
从后台
DAO
去数据
public
List queryByItem(
int itemid, int currentPage, int lineSize
)
throws
Exception {
//
TODO
Auto-generated method stub
List all =
null
;
String hql =
"FROM Question AS q WHERE q.itemid=?"
;
Query q =
super
.getSession().createQuery(hql);
q.setInteger(0, itemid);
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
all = q.list();
return
all;
}
经过
struts action
public
ActionForward selectitem(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List all =
null
;
int
currentPage = 1;
int
lineSize = 10;
int
allRecorders = 0;
try
{
currentPage = Integer.parseInt(request.getParameter("cp"));
}
catch
(Exception e) {
}
try
{
allRecorders = this.questiondao.getByItemCount(Integer
.parseInt(request.getParameter("itemid")));
all = this.questiondao.queryByItem(Integer.parseInt(request
.getParameter("itemid")), currentPage, lineSize);
}
catch
(NumberFormatException e) {
//
TODO
Auto-generated catch block
e.printStackTrace();
}
catch
(Exception e) {
//
TODO
Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("currentPage", currentPage);
request.setAttribute("lineSize", lineSize);
request.setAttribute("allRecorders", allRecorders);
request.setAttribute("all", all);
request.setAttribute("jspUrl", "show.do");
request.setAttribute("status", "selectitem");
request.setAttribute("flagname", "itemid");
request.setAttribute("flagvalue", request.getParameter("itemid"));
try
{
request.setAttribute(
"allitem"
,
this
.
itemdao
.queryAll());
}
catch
(Exception e) {
e.printStackTrace();
}
return
mapping.findForward(
"showlist"
);
}
在JSP页面嵌入相关代码
<
jsp:include
page
=
"split_page.jsp"
>
<
jsp:param
name
=
"
jspUrl
"
value
=
"${jspUrl}" />
<
jsp:param
name
=
"
lineSize
"
value
=
"${lineSize}"/>
每页显示条数
<
jsp:param
name
=
"
allRecorders
"
value
=
"${allRecorders}" />
<
jsp:param
name
=
"
keyWord
"
value
=
"<%=request.getAttribute("keyWord")%>" />
<
jsp:param
name
=
"
currentPage
"
value
=
"${currentPage}" />
<
jsp:param
name
=
"
status
"
value
=
"${status}" />
<
jsp:param
name
=
"
flagname
"
value
=
"${flagname}" />
<
jsp:param
name
=
"
flagvalue
"
value
=
"${flagvalue}" />
<
jsp:param
name
=
"searchFlag"
value
=
"T"
/>
</
jsp:include
>
分页程序部分代码
split_page.jsp
//
计算总页数
pageSize = (
allRecorders
+
lineSize
-1)/
lineSize
;
<
form
name
=
"spage"
action
=
"<%=jspUrl%>" onSubmit="change()">
<
input
type
=
"hidden"
name
=
"status"
value
=
"${status}"> <input type="hidden"
name
=
"${param.flagname}" value=${param.flagvalue}> <%
if
(
"T"
.equals(searchFlag)) {
%>
输入查询关键字:
<
input
type
=
"text"
name
=
"kw"
value
=
"<%=keyWord.equals("null") ? "" : keyWord%>"> <input
type
=
"submit"
value
=
"
查询
"
>
<
br
>
<
br
>
<%
if
(
allRecorders
> 0) {
%>
<
input
type
=
"button"
value
=
"
首页
"
onClick
=
"openPage(1)"
<%=
currentPage
== 1 ?
"disabled"
:
""
%>
>
<
input
type
=
"button"
value
=
"
上一页
"
onClick
=
"openPage(<%=currentPage - 1%>)"
<%=
currentPage
== 1 ?
"disabled"
:
""
%>
>
<
input
type
=
"button"
value
=
"
下一页
"
onClick
=
"openPage(<%=currentPage + 1%>)"
<%=
currentPage
== pageSize ?
"disabled"
:
""
%>
>
<
input
type
=
"button"
value
=
"
尾页
"
onClick
=
"openPage(<%=pageSize%>)"
<%=
currentPage
== pageSize ?
"disabled"
:
""
%>
>
<
input
type
=
"hidden"
name
=
"cp"
value
=
""
>
<
font
color
=
"red"
size
=
"5"
>
<%=
currentPage
%>
</
font
>
/
<
font
color
=
"red"
size
=
"5"
>
<%=
pageSize
%>
</
font
>
跳转到
<
select
name
=
"selpage"
onChange
=
"selOpenPage()"
>
<%
for
(
int
x = 1; x <= pageSize; x++) {
%>
<
option
value
=
"<%=x%>" <%=currentPage == x ? "selected" : ""%>><%=x%></option>
<%
}
%>
</
select
>
页
<%
}
%>
Spring Junit4测试
|
public class UserDAOTest extends AbstractDependencyInjectionSpringContextTests { @Override复写父类的方法,找到配制文件 protected String[] getConfigLocations() { // TODO Auto-generated method stub return new String[]{"classpath:applicationContext.xml"}; } //引入在Spring注入的bean private UserDAO userdao; public void setUserdao(UserDAO userdao) { this.userdao = userdao; } public void testLoadUser() throws Exception{ // User user=this.userdao.queryByUserid("fantlam"); // assertNotNull(user); boolean b=this.userdao.isExists("fantlam", "你在吗", "我在"); assertEquals(true,b); } //可以直接运行程序 public static void main(String[] args){ // junit.swingui.TestRunner.run(UserDAOTest.class);因为conmon-logging的原因,使用junit.awtui或junit.swingui包下的TestRunner会出现错误/ 故采用junit.textui包 junit.textui.TestRunner.run(UserDAOTest.class); } }
关于spring junit测试的类关系
org.springframework.test
Class AbstractTransactionalDataSourceSpringContextTests
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.springframework.test.ConditionalTestCase
org.springframework.test.AbstractSpringContextTests
org.springframework.test.AbstractSingleSpringContextTests
org.springframework.test.AbstractDependencyInjectionSpringContextTests
org.springframework.test.AbstractTransactionalSpringContextTests
org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
All Implemented Interfaces:
Test