模糊查询

js页面

$('.layui-btn').click(function () {
var inputVal = $('.layui-input').val()
table.reload('bookReload', {
url: '/stu/findStu'
,where: {
stuname : inputVal
}
});
})
Html页面
<div class="demoTable">
搜索:
<div class="layui-inline">
<input class="layui-input" name="keyword" id="demoReload" autocomplete="off">
</div>
<button class="layui-btn" data-type="reload">搜索</button>
</div>
(注:将搜索框放在table的上方,也就是body的第一行)

后台
  在全查询的基础上加上模糊搜索的参数(比如:根据name模糊搜索,就加上name这个参数)
Service层
public JsonData findStu(String stuname) {
if (stuname==null){
stuname="%%";
}else {
stuname="%"+stuname+"%";
}
List<Student> stu = stuMapper.findStu(stuname);
return JsonData.buildSuccess(stu);
}
mapper.xml
  sql语句:
SELECT t.*, s.username,s.pwd,s.stuname,s.sex,s.status FROM temperature t  right JOIN student s ON s.stuid = t.stuid
and stuname like #{stuname}


posted @ 2021-03-04 16:55  翘中之楚  阅读(75)  评论(0编辑  收藏  举报