search

Home  >  Q&A  >  body text

java - 如何在spring + mybatis 下进行数据库读写分离

如题。

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);
     }
}

如何通过配置实现读写分离,希望对现有代码框架影响小?

大家讲道理大家讲道理2895 days ago405

reply all(2)I'll reply

  • 阿神

    阿神2017-04-18 09:48:36

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:48:36

    You can refer to this article, which is very detailed.

    reply
    0
  • Cancelreply