@Service public class CollectionServiceImpl extends ServiceImpl<CollectionDao, Collection> implements ICollectionService { @Autowired CollectionDao collectionDao; @Override public void collectCollection(Collection collection) { Collection newCollection = new Collection(); newCollection.setCollectionSubjectId(collection.getCollectionSubjectId()); newCollection.setCollectionUserId(collection.getCollectionUserId()); collectionDao.insert(newCollection); } @Override public Collection isCollect(Integer collectionUserId,Integer collectionSubjectId) { LambdaQueryWrapper<Collection> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Collection::getCollectionUserId,collectionUserId).eq(Collection::getCollectionSubjectId,collectionSubjectId); return collectionDao.selectOne(wrapper); } @Override public Page<Map> getPageByUserId(Integer id, Integer currentPage, Integer pageSize) { Page<Map> objectPage = new Page<>(currentPage, pageSize); List<Map> maps = collectionDao.selectCollectionById(id); Integer pages = maps.size()/pageSize+1; Integer startIndex = (currentPage-1)*pageSize; objectPage.setTotal(maps.size()); // 判断是否最后一页并转入 if(currentPage ==pages){ objectPage.setRecords(maps.subList(startIndex,maps.size())); } else if(currentPage<pages){ objectPage.setRecords(maps.subList(startIndex,(startIndex+pageSize))); } return objectPage; } }
时间: 2023-12-26 11:04:32 浏览: 24
这段代码是一个收藏功能的实现,其中包括三个方法:
1. `collectCollection(Collection collection)`方法用于收藏一个主题(collectionSubjectId)。
2. `isCollect(Integer collectionUserId,Integer collectionSubjectId)`方法用于查询一个用户(collectionUserId)是否已经收藏了一个主题(collectionSubjectId)。
3. `getPageByUserId(Integer id, Integer currentPage, Integer pageSize)`方法用于分页查询一个用户(id)所收藏的主题,其中currentPage表示当前页码,pageSize表示每页显示的数量。
这个类使用了MyBatis-Plus提供的通用Mapper和分页插件,简化了数据访问层的代码。同时,它还为我们提供了一个方便的接口来实现收藏功能。
相关问题
@Service public class StayOutLateServiceImpl extends ServiceImpl<StayOutLateMapper, StayOutLate> implements StayOutLateService{ }请详细解释
这是一个Java类,使用了Mybatis-Plus框架中的ServiceImpl类作为基类,实现了StayOutLateService接口。该类主要用于对StayOutLate实体类在数据库中进行增删改查操作。
具体解释如下:
- @Service:该注解用于标注该类是一个服务层组件,供其他组件调用。
- public class StayOutLateServiceImpl extends ServiceImpl<StayOutLateMapper, StayOutLate>:这是一个类定义,它继承了Mybatis-Plus框架中的ServiceImpl基类,并指定泛型参数为StayOutLateMapper和StayOutLate,表示该类中要进行的数据库操作是针对StayOutLate实体类的。
- implements StayOutLateService:该类实现了StayOutLateService接口,表示该类中要实现该接口中声明的所有方法。
- StayOutLateMapper:该类中使用了StayOutLateMapper接口,用于对StayOutLate实体类在数据库中进行增删改查操作。该接口由Mybatis-Plus框架自动生成,可以通过继承BaseMapper接口来自定义。
- StayOutLate:该类中使用了StayOutLate实体类,表示该类中要进行的数据库操作是针对StayOutLate实体类的。StayOutLate实体类是一个JavaBean,用于存储StayOutLate表中的数据。它由开发者自己定义,需要与数据库中的StayOutLate表结构相对应。
@Service public class FormLogicService extends ServiceImpl<FormLogicMapper, FormLogic> { }
这段代码是一个 Spring Boot 服务中的一个服务类,名为 `FormLogicService`,继承了 `ServiceImpl<FormLogicMapper, FormLogic>` 类,用于提供对数据库中 `FormLogic` 表的访问操作。
注解 `@Service` 声明了该类为一个 Spring Bean,在 Spring 容器中进行管理。
`ServiceImpl<FormLogicMapper, FormLogic>` 继承了 `ServiceImpl<BaseMapper<T>, T>` 类,其中 `BaseMapper` 是 MyBatis 提供的基本的 Mapper 接口,`FormLogicMapper` 是继承自 `BaseMapper` 的自定义 Mapper 接口,用于访问 `FormLogic` 表。
`FormLogicService` 类中提供了一些对 `FormLogic` 表的操作,如插入、更新、删除和查询等。这些操作都继承自 `ServiceImpl` 类。
由于 `FormLogicService` 继承了 `ServiceImpl`,因此无需在该类中手动编写对 `FormLogic` 表的增删改查代码,而是可以直接调用 `ServiceImpl` 类中定义好的方法。这避免了重复代码和提高了开发效率。同时,如果需要自定义一些操作,也可以在 `FormLogicService` 类中手动编写相应的方法。