Mybatis Xml 传入动态字段 排序

太原  2019.6-28

 

主要思路是 使用${} ,

#{}传过来的参数带单引号'',而${}传过来的参数不带单引号。

下面是Mybatis中Xml格式的写法

#{}  ${} 可以混用,  好像不太建议 ,不过就是这么一回事

	

Controller

@RequestMapping("/searchTermList")
	public ModelAndView searchTermList(
			@RequestParam(value = "pageNo", required = false, defaultValue = "1")String pageNo,
			@RequestParam(required=false, value="goodClass",defaultValue="")String goodClass,
			@RequestParam(required=false, value="tradeType",defaultValue="")String tradeType,
			@RequestParam(required=false, value="position",defaultValue="")String position,
			@RequestParam(required=false, value="filterItem",defaultValue="")String filterItem,
			@RequestParam(required=false, value="filterSort",defaultValue="")String filterSort) {

		ModelAndView model = new ModelAndView("html5/bookContact/contactMemberList-page");
		Pager pagerMember = new Pager();
		pagerMember.setPageSize(5);
		pagerMember.setPageNo(Integer.parseInt(pageNo));

		BookContactMember Member = new BookContactMember();
		Member.setIsFamous("1");//设置查询条件 大腕
		Member.setCompanyPosition(position);//职务
		Member.setTradeType(position);//职务
		Member.setTradeType(tradeType);//行业
		Member.setGoodsClass(goodClass);//产品 (一级分类)
		//判断排序字段
		if(StringUtils.isNotBlank(filterItem)){
			if(StringUtils.equalsIgnoreCase(filterItem,"readNum")){
				Member.setFilterItem("read_num");
			}
			if(StringUtils.equalsIgnoreCase(filterItem,"needNum")){

				Member.setFilterItem("need_num");
			}
			if(StringUtils.equalsIgnoreCase(filterItem,"bbsNum")){
				Member.setFilterItem("bbs_num");
			}
			//判断排序的顺序
			if(StringUtils.isNotBlank(filterSort)){
				//1是正序  0是倒序
				if(StringUtils.equalsIgnoreCase(filterSort,"1")){
					Member.setSortItem(Integer.parseInt(filterSort));
				}
				if(StringUtils.equalsIgnoreCase(filterSort,"0")){
					Member.setSortItem(Integer.parseInt(filterSort));
				}
			}

		}

		pagerMember.setCondition(Member);
		List bookMemberPageList = bookContactMemberService.findBookMemberPagerConditionList(pagerMember);
}

 

 

你可能感兴趣的:(Mybatis,Java,太原历练)