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;
}
(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;
} else {
mui.alert('您输⼊的信息查询不到相关分组,请重新输⼊');
}
} else if (res.json().code != null && res.json().code == "1111") {
mui.alert('获取分组信息失败,请重试');
};
}
)
}
⼆、后端接收参数:设置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 (im()) {
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) {
<("查询分组情况异常", e);
return ItooResult.build("1111", "查询分组情况失败");
}
}
Mapper层:⽤if条件判断是否查询
<!--模糊查询所有的分组(⽬前考虑的条件只有学年,之后⼀定会有变动)-->
<select id="findGroupByGroupName" resultType="com.dmsdbj.ity.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
param nameschool_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>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论