不多说直接上代码!
接口:
public interface CommodityMapper { int deleteByPrimaryKey(Integer productId); int insert(Commodity record); Commodity selectByPrimaryKey(Integer productId); ListselectAll(); List getType(int id); int updateByPrimaryKey(Commodity record); int getCount(); List SearchCommodity(@Param("productName") String productName);//注意传参的名字必须要和Mapper文件一致 }
Constroller层:
//搜索 @RequestMapping(path = "/search", method = RequestMethod.GET) public ResponseEntity Search(String productName) { if (commodityService.SearchCommodity(productName).size() != 0) { return ResponseEntity.ok(commodityService.SearchCommodity(productName)); } else { return ResponseEntity.ok("error"); } }
Mapper文件