是的,Mybatis-Plus service层通常需要注入mapper。这是因为service层常常需要调用mapper中的方法来访问数据库,而在Spring中,我们通常使用依赖注入来实现对象之间的解耦。因此,我们通常在service层中注入mapper对象,以便在service层中使用mapper中的方法。

你可以使用@Autowired注解来将mapper对象注入到service层中,例如:

@Autowired
private UserMapper userMapper;

然后,就可以在service层中使用userMapper对象调用mapper中的方法了。

例如:

List<User> users= userMapper.selectList(null);
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐