pub struct ServiceImpl<E, T>{ /* 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>
impl<E, T> ServiceImpl<E, T>
Sourcepub fn new(executor: E, table_name: impl Into<String>) -> ServiceImpl<E, T>
pub fn new(executor: E, table_name: impl Into<String>) -> ServiceImpl<E, T>
Sourcepub fn with_id_column(self, column: impl Into<String>) -> ServiceImpl<E, T>
pub fn with_id_column(self, column: impl Into<String>) -> ServiceImpl<E, T>
设置主键列名(默认 “id”)。
Sourcepub fn table_name(&self) -> &str
pub fn table_name(&self) -> &str
获取表名。
Trait Implementations§
Source§impl<E, T> IService<T> for ServiceImpl<E, T>
impl<E, T> IService<T> for ServiceImpl<E, T>
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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>
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>
impl<E, T> UnsafeUnpin for ServiceImpl<E, T>
impl<E, T> UnwindSafe for ServiceImpl<E, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more