Springboot+vue的模糊查询方法

1.html代码

<td colspan="3" align="center"><input type="text" v-model="name">
 <input type="button"  value="查询" v-on:click="dataListFn(1)"></td>

2.vue代码(再data中添加元素 name:"",从查查询方法中定义)

 $.post("/stu/pageList",{NowPage:page,name:this.name},function (data) {

此处只为加入name:this.name
3.dao service controller中
dao方法

@Query(value = "select *  from stu s  inner join class c   on c.cid = s.scid where name   LIKE CONCAT('%',:name,'%') ",nativeQuery = true) //分页表连接
    Page<List<Map>> findAllDataPage(Pageable pageable,String name);
}

service方法

 public Page<List<Map>> findAllMap(Pageable pageable,String name){ return stuDao.findAllDataPage(pageable,name); }

controller

@RequestMapping("/pageList")
    @ResponseBody
    public Page<List<Map>> pageList(HttpServletRequest request,String name){
        Sort sort = null;
        request.getParameter("name");
        sort = new Sort(Sort.Direction.DESC,"uuid");
        Integer NowPage = Integer.parseInt(request.getParameter("NowPage"));
        System.out.println(NowPage);
        Pageable Page = PageRequest.of(NowPage-1,2,sort);//此处的2是控制每页显示多少条,nowpage-1是默认显示第一页
        Page<List<Map>> data = stuService.findAllMap(Page,name);
        return data;
    }

你可能感兴趣的:(Java,框架学习)