如题。
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);
}
}
如何通过配置实现读写分离,希望对现有代码框架影响小?
spring配置dataSource那里多配置几个dataSource,通过方法名判断是走读库还是写库,类似事务控制。