如题。
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);
}
}
如何通过配置实现读写分离,希望对现有代码框架影响小?
スプリング構成 dataSource でさらにいくつかの dataSource を構成します。トランザクション制御と同様に、メソッド名を使用して読み取りライブラリか書き込みライブラリかを判断します。
非常に詳しく説明されているこの記事を参照してください。