1.作用:
(1)能夠設(shè)置緩存時(shí)間;
(2)能夠?yàn)閷?duì)象生成自增的主鍵值;
2.應(yīng)用場(chǎng)景:
(1).插入時(shí)使用,eg:插入一件商品并返回主鍵值
//useGeneratedKeys :默認(rèn) false ,作用:設(shè)置是否使用JDBC的getGenereatedKeys方法獲取主鍵并賦值到keyProperty設(shè)置的領(lǐng)域模型屬性中。
//keyProperty、keyColumn:返回的字段。
@Options(useGeneratedKeys=true, keyProperty="goodsId", keyColumn="goods_id")
@Insert("insert into goods (supplier_id,category_id,fabric_id,goods_name,goods_img_url,wholesale_min_number,sales_seven_days,sales_total,sale_price,purchase_price,goods_no,goods_status,video_url,origin_id,origin_name,weight,market_id,estimate_weight,has_video) values(#{supplierId},#{categoryId},#{fabricId},#{goodsName},#{goodsImgUrl},#{wholesaleMinNumber},#{salesSevenDays},#{salesTotal},#{salePrice},#{purchasePrice},#{goodsNo},#{goodsStatus},#{videoUrl},#{originId},#{originName},#{weight},#{marketId},#{estimateWeight},#{hasVideo})")
Long addGoods(@Param("supplierId") Integer supplierId,@Param("categoryId") Integer categoryId,@Param("fabricId") Integer fabricId,@Param("goodsName") String goodsName,@Param("goodsImgUrl") String goodsImgUrl,@Param("wholesaleMinNumber") Integer wholesaleMinNumber,@Param("salesSevenDays") int salesSevenDays,@Param("salesTotal") int salesTotal,@Param("salePrice") Long salePrice,@Param("purchasePrice") Long purchasePrice,@Param("goodsNo") String goodsNo,@Param("goodsStatus") int goodsStatus,@Param("videoUrl") String videoUrl,@Param("originId") Integer originId,@Param("originName") String originName,@Param("weight") Long weight,@Param("marketId") Integer marketId,@Param("estimateWeight") Long estimateWeight,@Param("hasVideo") Integer hasVideo);
(2).查詢(xún)時(shí)使用:
//useCache=true,表示會(huì)緩存本次查詢(xún)結(jié)果;
//flushCache=Options.FlushCachePolicy.FALSE,表示查詢(xún)時(shí)不會(huì)刷新緩存;
//timeout=10000,表示查詢(xún)結(jié)果緩存10000秒;
@Options(useCache=true,flushCache=Options.FlushCachePolicy.FALSE,timeout=10000)