Skip to main content

ServiceImpl

Struct ServiceImpl 

Source
pub struct ServiceImpl<E, T>
where E: Executor + Send + Sync + Clone + 'static, T: Serialize + DeserializeOwned + Send + Sync,
{ /* private fields */ }
Expand description

Service 实现基类(对标 Java ServiceImpl<M, T>)。

提供 IService<T> trait 的默认实现,基于 rbatis Executor 执行数据库操作。

  • E — Executor 类型(RBatis、RBatisConnExecutor、RBatisTxExecutor 等)
  • T — 实体类型

§对应 Java

  • com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M, T>

§Example

ⓘ
use rbatis_plus_extension::service::{ServiceImpl, IService};

struct UserService {
    inner: ServiceImpl<rbatis::RBatis, User>,
}

impl UserService {
    pub fn new(rb: rbatis::RBatis) -> Self {
        Self {
            inner: ServiceImpl::new(rb, "sys_user"),
        }
    }
}

Implementations§

Source§

impl<E, T> ServiceImpl<E, T>
where E: Executor + Send + Sync + Clone + 'static, T: Serialize + DeserializeOwned + Send + Sync,

Source

pub fn new(executor: E, table_name: impl Into<String>) -> ServiceImpl<E, T>

创建 ServiceImpl 实例。

§参数
  • executor: 数据库执行器(RBatis / ConnExecutor / TxExecutor)
  • table_name: 数据库表名
Source

pub fn with_id_column(self, column: impl Into<String>) -> ServiceImpl<E, T>

设置主键列名(默认 “id”)。

Source

pub fn table_name(&self) -> &str

获取表名。

Source

pub fn id_column(&self) -> &str

获取主键列名。

Source

pub fn executor(&self) -> &E

获取执行器引用。

Trait Implementations§

Source§

impl<E, T> IService<T> for ServiceImpl<E, T>
where E: Executor + Send + Sync + Clone + 'static, T: Serialize + DeserializeOwned + Send + Sync,

Source§

fn save<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, ServiceImpl<E, T>: 'async_trait,

插入一条记录(对标 Java ServiceImpl.save())。

Source§

fn save_or_update<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, ServiceImpl<E, T>: 'async_trait,

插入或更新(根据 ID 判断)(对标 Java ServiceImpl.saveOrUpdate())。

Source§

fn remove_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 Value, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据 ID 删除(对标 Java ServiceImpl.removeById())。

Source§

fn remove<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, wrapper: &'life1 QueryWrapper, table_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据条件删除(对标 Java ServiceImpl.remove(Wrapper))。

Source§

fn update_by_id<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据 ID 更新(对标 Java ServiceImpl.updateById())。

Source§

fn update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, wrapper: &'life1 UpdateWrapper, table_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据条件更新(对标 Java ServiceImpl.update(Wrapper))。

Source§

fn get_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 Value, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据 ID 查询(对标 Java ServiceImpl.getById())。

Source§

fn list<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, wrapper: &'life1 QueryWrapper, table_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据条件查询列表(对标 Java ServiceImpl.list(Wrapper))。

Source§

fn get_one<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, wrapper: &'life1 QueryWrapper, table_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ServiceImpl<E, T>: 'async_trait,

根据条件查询单条(对标 Java ServiceImpl.getOne(Wrapper))。

Source§

fn count<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, wrapper: &'life1 QueryWrapper, table_name: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ServiceImpl<E, T>: 'async_trait,

查询总数(对标 Java ServiceImpl.count(Wrapper))。

Source§

fn page<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, wrapper: &'life1 QueryWrapper, table_name: &'life2 str, page_no: u64, page_size: u64, ) -> Pin<Box<dyn Future<Output = Result<Page<T>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, ServiceImpl<E, T>: 'async_trait,

分页查询(对标 Java ServiceImpl.page(Wrapper, Page))。

Auto Trait Implementations§

§

impl<E, T> Freeze for ServiceImpl<E, T>
where E: Freeze, PhantomData<T>: Freeze,

§

impl<E, T> RefUnwindSafe for ServiceImpl<E, T>

§

impl<E, T> Send for ServiceImpl<E, T>
where PhantomData<T>: Send,

§

impl<E, T> Sync for ServiceImpl<E, T>
where PhantomData<T>: Sync,

§

impl<E, T> Unpin for ServiceImpl<E, T>
where E: Unpin, PhantomData<T>: Unpin,

§

impl<E, T> UnsafeUnpin for ServiceImpl<E, T>

§

impl<E, T> UnwindSafe for ServiceImpl<E, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.