概述

搜索后的新页面,一般情况下搜索条件的值都会被设置为空,但是如果想修改上一次搜索的条件再搜索,就需要获取到上一次的搜索条件

实现过程

代码

HTML代码(只有搜索form标签的代码,显示数据的代码已删除)

th:value获取上一次搜索条件的值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<form action="/toGoodsManagePage" method="post">
<div class="row" style="margin-left: 3px">
<input type="text" class="form-control" id="nameSearchGoods" name="name" style="width: 200px"
th:value="${name}"
placeholder="请输入商品名称...">
<select id="goodsTypeIdSearchGoods" name="goodsTypeId" th:value="${goodsTypeId}"
style="width: 200px;margin-left: 2px" class="form-control">
<option value="">选择商品类别...</option>
<div th:each="goodsType:${goodsTypeList}">
<option th:text="${goodsType.name}" th:value="${goodsType.id}" th:selected="${goodsTypeId==goodsType.id}"></option>
</div>
</select>
<select id="stateSearchGoods" name="state" th:value="${state}" style="width: 200px;margin-left: 2px"
class="form-control">
<option value="">选择商品状态...</option>
<div>
<option value="0" th:selected="${state==0}">未审核</option>
<option value="1" th:selected="${state==1}">上架中</option>
<option value="2" th:selected="${state==2}">审核不通过</option>
<option value="3" th:selected="${state==3}">已下架</option>
<option value="4" th:selected="${state==4}">交易完成</option>
</div>
</select>
<select id="isRecommendSearchGoods" name="isRecommend" th:value="${recommend}" style="width: 200px;margin-left: 2px"
class="form-control">
<option value="">商品是否被推荐...</option>
<div>
<option value="0" th:selected="${recommend==0}">不推荐</option>
<option value="1" th:selected="${recommend==1}">被推荐</option>
</div>
</select>
<button type="submit" class="btn btn-primary status-icon hint--top" style="margin-left: 2px" aria-label="搜索"><i class="fa fa-search"></i>
</button>
<a href="javascript:resetSearchGoodsValue()"><button type="button" class="btn btn-info status-icon hint--top" aria-label="重置" style="margin-left: 2px"><i class="fa fa-rotate-right"></i></button></a>
</div>
</form>

Java代码(只保留了向页面传值的代码,其它业务代码已删除)

ModelAndView.addObject(String 参数一,String 参数二)方法向页面传值,参数一为键,参数二为值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* 跳转到我的商品管理界面
*
* @return
*/
@RequestMapping("/toGoodsManagePage")
public ModelAndView toGoodsManagePage(HttpSession session, Goods searchGoods) {
ModelAndView mav = new ModelAndView();
if (searchGoods.getName() != null) {
goodsQueryWrapper.like("name", searchGoods.getName());
mav.addObject("name", searchGoods.getName());
}
if (searchGoods.getGoodsTypeId() != null) {
goodsQueryWrapper.eq("goodsTypeId", searchGoods.getGoodsTypeId());
mav.addObject("goodsTypeId", searchGoods.getGoodsTypeId());
}
if (searchGoods.getState() != null) {
goodsQueryWrapper.eq("state", searchGoods.getState());
mav.addObject("state", searchGoods.getState());
}
if (searchGoods.getIsRecommend() != null) {
goodsQueryWrapper.eq("isRecommend", searchGoods.getIsRecommend());
mav.addObject("recommend", searchGoods.getIsRecommend());
}
mav.addObject("title", "我的商品管理--LeDao校园二手交易平台");
mav.addObject("mainPage", "page/goodsManage");
mav.addObject("mainPageKey", "#b");
mav.setViewName("index");
return mav;
}

效果

 javascript