Get Started With Smartdao

  1. pom文件中添加倉庫地址
<repositories>
        <repository>
            <id>september</id>
            <name>Spring Snapshots</name>
            <url>http://120.92.166.27:9081/nexus/content/groups/public/</url>
        </repository>
</repositories>
  1. 添加最新版本的maven依賴
<dependency>
    <groupId>org.september</groupId>
    <artifactId>alliance-smartdao</artifactId>
    <version>2.3.1-SNAPSHOT</version>
</dependency>
  1. 配置數(shù)據(jù)源
#方言設(shè)置
spring.alliance.dao.dialect=mysql

#因為支持多數(shù)據(jù)源,所以對數(shù)據(jù)源做了個分組的功能,每個數(shù)據(jù)源配置自己所屬的分組,每個分組下有多個數(shù)據(jù)源,通常是一個寫,多個讀。
#如果有多個數(shù)據(jù)源需要從0,1,2,3依次增加
spring.alliance.dao.datasource[0].group = logdog
#可以是read, write, write/read 三種之一
spring.alliance.dao.datasource[0].type = write/read
spring.alliance.dao.datasource[0].driverClass=com.mysql.cj.jdbc.Driver
spring.alliance.dao.datasource[0].jdbcUrl = jdbc:mysql://localhost:3306/logdog?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
spring.alliance.dao.datasource[0].username = root
spring.alliance.dao.datasource[0].password = ********

  1. 在你的service類中注入CommonDao
@Autowired
private CommonDao commonDao;
  1. 使用CommonDao保存數(shù)據(jù)
  // User是一個實體類
  User user = new User();
  user.setName("xzye");
  commonDao.save(user);

mapper文件的默認(rèn)保存路徑是 classpath:/mybatis/mapper/ 下,我們建議以約定的方式,大家把mapper文件都放在這個目錄下。當(dāng)然也可以通過實現(xiàn)MyBatisConfigManager接口的方式來修改。

User是一個實體類,實體類如何定義以及支持的特性,請閱讀 實體類的使用 一文。
CommonDao中更多api的使用方法,請閱讀 CommonDao Api詳解 一文

Smartdao源碼地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容