jsp脚本和java解决排序

<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代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值