如题。
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를 구성합니다. 트랜잭션 제어와 마찬가지로 메서드 이름을 사용하여 읽기 라이브러리인지 쓰기 라이브러리인지 확인합니다.
이 글을 참고하시면 아주 자세하게 나와있습니다.