如题。
Dao层代码由mybatis-generator-core自动生成,并由spring管理,调用的时候类似这样:
@Service("articleService") public class ArticleServiceImpl implements ArticleService { @Autowired ArticleMapper articleMapper; public void update(Integer id){ //一个方法里可能有查询和更新 Article article = articleMapper.selectByPrimaryKey(id); articleMapper.updateByPrimaryKeySelective(article); } }
如何通过配置实现读写分离,希望对现有代码框架影响小?
Configure several more dataSources in the spring configuration dataSource. Use the method name to determine whether it is a reading library or a writing library, similar to transaction control.
You can refer to this article, which is very detailed.