- Add CosIdPlugin(cosid-mybatis) to support automatic injection of distributed IDs through annotations
@Target({ElementType.FIELD})
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface CosId {
String value() default IdGeneratorProvider.SHARE;
boolean friendlyId() default false;
}
public class Order {
@CosId
private long id;
@CosId
private String stringId;
@CosId(friendlyId = true)
private String friendlyId;
@CosId(value = "bizC")
private long bizId;
/**
* ...
* getter or setter
*/
}
@Mapper
public interface OrderRepository {
@Insert("insert into t_order (id,string_id,friendly_id,biz_id) value (#{id},#{stringId},#{friendlyId},#{bizId});")
void insert(Order order);
@Insert({
"<script>",
"insert into t_order (id,string_id,friendly_id,biz_id)",
"VALUES" +
"<foreach item='item' collection='list' open='' separator=',' close=''>" +
"(#{item.id},#{item.stringId},#{item.friendlyId},#{item.bizId})" +
"</foreach>",
"</script>"})
void insertList(List<Order> orderList);
}
Order order=new Order();
orderRepository.insert(order);
/**
* {
* "id": 213044050087903230,
* "stringId": "213044050087903233",
* "friendlyId": "20210803212059708-0-2",
* "bizId": 28801
* }
*/
return order;