<img class ="arror"alt="now not to see" src="<%=request.getAttribute("SORT").equals("up") ? Constants.UP : Constants.DOWN %>"/>
HTML代码
要达到的效果,点击img(排序的箭头),升序降序排列(暂未解决排序之后的分页:之后再做,也就是是在分页的时候需要带着SORT走)
$(".arror").click(function() {
var src = $(this).attr("src") == "static/image/common/1.PNG" ? "static/image/common/3.PNG" : "static/image/common/1.PNG";
$(this).attr("src", src);
var sort = src == "static/image/common/1.PNG" ? "up" : "down";
window.location.href = "index.action?sort=" + sort;
});
js代码
public ModelAndView index(Map<String, Object> request, Map<String, Object> session) {
System.out.println("index");
ModelAndView modelAndView = new ModelAndView();
String keywords = (String) request.get(Constants.QUESTION_KEYWORDS);
String currentPage = (String) request.get(Constants.CURRENTPAGE);
String page = (String) request.get(Constants.PAGE); // Handle GO
String sort = (String) request.get(Constants.SORT);
User user = (User) session.get(Constants.USER);
PageBean pagebean = new PageBean();
if (!StringUtil.isEmpty(keywords)) {
// User doing fuzzy query
int count = questionService.findCountQuestionByKeywords(keywords, user.getUserId());
modelAndView.addObject(Constants.KEYWORDS, keywords);
if (count == 0) {
// When fuzzy query = 0
modelAndView.addObject(Constants.NO_QUESTIONLIST_FOUND, Constants.NO_QUESTIONLIST_FOUND_MESSAGE );
} else { // When fuzzy query != 0
pagebean.setCurrentPage(1);
pagebean.setPagesize(10);
pagebean.setTotalcount(count);
modelAndView.addObject(Constants.PAGEBEAN, pagebean);
List<Question> questionList =
questionService.findQuestionByKeywords(keywords, user.getUserId(), pagebean);
modelAndView.addObject(Constants.QUESTION_LIST, questionList);
}
} else {
// General treatment go into index.jsp
pagebean.setCurrentPage(1);
if (!StringUtil.isEmpty(currentPage)) {
int currentPagevalue = Integer.parseInt(currentPage);
pagebean.setCurrentPage(currentPagevalue);
}
if (!StringUtil.isEmpty(page)) {
int pagevalue = Integer.parseInt(page);
if (pagevalue != 0) {
pagebean.setCurrentPage(pagevalue);
}
}
int count = questionService.findQuestionCount(user.getUserId());
if (count == 0) {
// user login have no questionlist
modelAndView.addObject(Constants.NO_QUESTION, Constants.NO_QUESTION_MESSAGE);
} else {
pagebean.setPagesize(Integer.parseInt(PropertiesUtil.readProperty("pageSize")));
pagebean.setTotalcount(count);
List<Question> questionList = null;
modelAndView.addObject(Constants.SORT_BIG, "down");
if (!StringUtil.isEmpty(sort)) {
// Ascending order
if ("up".equals(sort)) {
modelAndView.addObject(Constants.SORT_BIG, sort);
questionList = questionService.findQuestionByIdUp(user.getUserId(), pagebean);
}else {
questionList = questionService.findQuestionById(user.getUserId(), pagebean);
}
}else {
questionList = questionService.findQuestionById(user.getUserId(), pagebean);
}
modelAndView.addObject(Constants.PAGEBEAN, pagebean);
modelAndView.addObject(Constants.QUESTION_LIST, questionList);
}
}
modelAndView.setRedirect(true);
modelAndView.setView(Constants.GO_INDEX_PAGE);
return modelAndView;
}
java代码