url传递参数时,设置参数可以传值为空

设置最后一个参数groupName可以传值或为空

一、前端传值方式:

使用:

if (this.searchgroupinfo === "" || this.searchgroupinfo === null || this.searchgroupinfo === undefined) {
      selectGroupUrl = 'physical-web/group/findGroupByGroupName/' + batchNo + '/' + this.studentSex;
} else {
      selectGroupUrl = 'physical-web/group/findGroupByGroupName/' + batchNo + '/' + this.studentSex + '?groupName=' + this.searchgroupinfo;

例子:

//查询分组信息
searchGroupName() {
    this.searchgroupinfo = this.searchContent;
    let selectGroupUrl: string;
    let batchNo = this.currentBatchNo;
    if (this.searchgroupinfo === "" || this.searchgroupinfo === null || this.searchgroupinfo === undefined) {
      selectGroupUrl = 'physical-web/group/findGroupByGroupName/' + batchNo + '/' + this.studentSex;
    } else {
      selectGroupUrl = 'physical-web/group/findGroupByGroupName/' + batchNo + '/' + this.studentSex + '?groupName=' + this.searchgroupinfo;
    }
    this.http.get(selectGroupUrl).subscribe(
      res => {
        if (res.json().code != null && res.json().code == "0000") {
          let data: any;
          data = res.json().data;
          if (data != null && data.length > 0) {
            this.searchGroup = res.json().data;
            document.getElementById("groupNameList").style.display = 'block';
          } else {
            mui.alert('您输入的信息查询不到相关分组,请重新输入');
            document.getElementById("groupNameList").style.display = 'none';
          }
        } else if (res.json().code != null && res.json().code == "1111") {
          mui.alert('获取分组信息失败,请重试');
          document.getElementById("groupNameList").style.display = 'none';
        };
      }
    )
  }

二、后端接收参数:设置groupName默认为空

controller层:

@ResponseBody
    @RequestMapping(value = {"/findGroupByGroupName/{batchNo}/{groupSex}"}, method = RequestMethod.GET)
    @ApiOperation(value = "模糊搜索查询分组情况是否成功", notes = "输入分组的批次,分组的性别,分组的部分名称", tags = {"查询"})
    public ItooResult findGroupByGroupName(
            @ApiParam(name = "batchNo", value = "分组的批次", required = true) @PathVariable String batchNo,
            @ApiParam(name = "groupSex", value = "分组的性别", required = true) @PathVariable String groupSex,
            @ApiParam(name = "groupName", value = "分组的部分名称") @RequestParam(required = false, defaultValue = "") String groupName) {
        List<GroupEntity> groupNameEntityList;
        try {
            switch (groupSex.trim()) {
                case "1":
                    groupSex = "男";
                    break;
                case "2":
                    groupSex = "女";
                    break;
                case "0":
                    groupSex = "";
                    break;
                default:
                    break;
            }
            groupNameEntityList = groupFacade.findGroupByGroupName(batchNo, groupSex, groupName);
            if (groupNameEntityList != null && groupNameEntityList.size() > 0) {
                return ItooResult.build("0000", "查询分组情况成功", groupNameEntityList);
            } else if (groupNameEntityList != null) {
                return ItooResult.build("0000", "查询分组情况为空", groupNameEntityList);
            } else {
                return ItooResult.build("1111", "查询分组情况失败");
            }
        } catch (Exception e) {
            logger.error("查询分组情况异常", e);
            return ItooResult.build("1111", "查询分组情况失败");
        }
    }

Mapper层:用if条件判断是否查询

    <!--模糊查询所有的分组(目前考虑的条件只有学年,之后一定会有变动)-->
    <select id="findGroupByGroupName" resultType="com.dmsdbj.itoo.physical.entity.GroupEntity">
        SELECT
        id,
        group_name AS groupName,
        batch_no AS batchNo,
        begin_date AS beginDate,
        end_date AS endDate,
        grade_no AS gradeNo,
        school_year AS schoolYear,
        sex,
        operator,
        is_delete AS isDelete,
        create_time AS createTime,
        update_time AS updateTime
        FROM tp_group
        WHERE is_delete = 0 AND
        school_year = #{schoolYear} AND
        batch_no=#{batchNo} AND
        #{date} BETWEEN begin_date AND end_date
        <if test="groupSex != null and groupSex != ''">
            AND sex = #{groupSex}
        </if>
        <if test="groupName != null and groupName != ''">
            AND group_name LIKE concat('%',#{groupName},'%')
        </if>
        ORDER BY group_name
    </select>

 

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值