@options

1.作用:
(1)能够设置缓存时间;
(2)能够为对象生成自增的主键值;

2.应用场景:
(1).插入时使用,eg:插入一件商品并返回主键值

 

        //useGeneratedKeys :默认 false ,作用:设置是否使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。
       //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).查询时使用:

 

//useCache=true,表示会缓存本次查询结果;
//flushCache=Options.FlushCachePolicy.FALSE,表示查询时不会刷新缓存;
//timeout=10000,表示查询结果缓存10000秒;
@Options(useCache=true,flushCache=Options.FlushCachePolicy.FALSE,timeout=10000)

 

你可能感兴趣的:(java)