控制层中:
// 根据店家id查找图书,已售数量要大于等于1才显示 List<SoldBook> sbList = shopService.getSoldBookByShopidAndBookName( shopid, bname);
服务层中:
//通过搜索图书名重载数据表格 public List<SoldBook> getSoldBookByShopidAndBookName(int shopid, String bname) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("sid", shopid); map.put("bname", bname); List<Book> books = bookMapper.getSoldBookByShopidAndBookName(map); ArrayList<SoldBook> list = new ArrayList<SoldBook>();}
mapper.xml中:
<!-- 通过搜索图书名得到销售数量大于0的指定店家的图书数据 --> <!-- 其中hashmap是mybatis自己配置好的,用来传递多个不同类型的参数 --> <!-- 模糊查询要这样写:b.longname like concat(concat('%',#{bname}),'%') --> <select id="getSoldBookByShopidAndBookName" parameterType="java.util.HashMap" resultMap="BookWithPicAndShopResultMap"> select <include refid="BookWithPicAndShop_Column_List" /> from t_book b, t_shop s, t_picture p, t_categorytwo c where b.shopid = s.shopid and b.picid = p.picid and b.pass = "通过" and b.categoryid = c.twoid and b.sold > 0 and s.shopid = #{sid, jdbcType=INTEGER} and b.longname like concat(concat('%',#{bname}),'%') </select>