mybatisplus service层需要注入mapper么
是的,Mybatis-Plus service层通常需要注入mapper。这是因为service层常常需要调用mapper中的方法来访问数据库,而在Spring中,我们通常使用依赖注入来实现对象之间的解耦。因此,我们通常在service层中注入mapper对象,以便在service层中使用mapper中的方法。你可以使用@Autowired注解来将mapper对象注入到service层中,例如:.
·
是的,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);
更多推荐
已为社区贡献8条内容
所有评论(0)