按照id查询
按照id查询 http://localhost:8888/singer/queryByName?name=王
@RequestMapping("/queryByName") public List<Singer> queryByName(String name) { LambdaQueryWrapper<Singer> lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.like(Singer::getName,name); List<Singer> singers = service.list(lambdaQueryWrapper); return singers; }
编写添加记录的方法
@PostMapping("/save") public String save(HttpServletRequest request) { Singer singer = new Singer(); singer.setName(request.getParameter("name")) .setSex(Integer.parseInt(request.getParameter("sex"))) .setPic(request.getParameter("pic")) .setBirth(new Date()) .setLocation(request.getParameter("location")) .setIntroduction(request.getParameter("introduction")); boolean save = service.save(singer); String result = save == true ? "添加成功" : "添加失败"; return result; }
修改方法
修改 http://localhost:8888/singer/update?id=64&introduction=歌声甜美
@RequestMapping("/update") public String update(int id, String introduction, HttpServletRequest request) { LambdaUpdateWrapper<Singer> lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); lambdaUpdateWrapper.eq(Singer::getId,id) .set(Singer::getIntroduction,introduction); boolean update = service.update(lambdaUpdateWrapper); String result = update == true ? "修改成功" : "修改失败"; return result; }
删除方法
删除 http://localhost:8888/singer/delete?id=64
@RequestMapping("/delete") public String delete(Integer id) { boolean remove = service.removeById(id); String result = remove == true ? "删除成功" : "删除失败"; return result; }