記一次mybatis-plus操作sqlite(windows共享 掛載至 linux服務器);前提是windows主機和linux主機網絡可以互通的


  • 進行windows目錄共享,設置專用用戶名和密碼(sqliteuser/123456)
    • 進入windows文件夾進行共享設置

 

 

    •  進入高級共享設置共享名

 

 

    •  配置共享權限用戶(本地用戶創建自己百度一下),一定要配置為 ‘完全控制’


 

 

 

  • 對windows共享文件進行掛載(samba協議)
    • 臨時掛載:
      • 創建目標目錄
        mkdir -p /mnt/sqlite/db0 
      • 進行掛載共享目錄
        mount -t cifs //${ip}/sqllite /mnt/sqlite/db0 -o username=sqliteuser,password=123456,nobrl,iocharset=utf8,uid=0,gid=0(nobrl很關鍵,要不然后期sqlite會出現 ‘write時 dbfile lock’
      • 測試目錄掛載是否到位
        ls -l /mnt/sqlite/db0
      • 卸載掛載(如果需要對該目標目錄進行重新掛載,建議先卸載)
        umount /mnt/sqlite/db0 (如果出現target busy,則需要將占用該目錄的linux進程進行kill)
    • 永久掛載:
      • 創建目標目錄
        mkdir -p /mnt/sqlite/db0 
      • 修改 /etc/fstab 文件
        echo "//${ip}/sqllite  /mnt/sqlite/db0 cifs  defaults,username=sqliteuser,password=123456,nobrl,iocharset=utf8,uid=0,gid=0 0 0" >> /etc/fstab
      • 將掛載文件/etc/fstab生效
        mount -a 
      • 卸載掛載(如果需要對該目標目錄進行重新掛載,建議先卸載)
        umount /mnt/sqlite/db0 (如果出現target busy,則需要將占用該目錄的linux進程進行kill)

 

  • 新建mapper、service對sqlite進行操作

 

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import xxx.entity.MesProdSqlLitePqcStandard;

/**
* @Description: PCB類型對應的標准Mapper (調用mapper前需要切換數據源)
* @Author: wqc
* @Date: 2022-03-01
* @Version: V1.0
*/
public interface MesProdSqlLitePqcStandardMapper extends BaseMapper<MesProdSqlLitePqcStandard> {

}

 
        
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import xxx.entity.MesProdSqlLitePqcStandard;

import xxx.mapper.MesProdSqlLitePqcStandardMapper;
import xxx.service.IMesProdSqlLitePqcStandardService;
import org.springframework.transaction.annotation.Propagation;

/**
* @Description: PCB類型對應的標准Service (調用mapper前需要切換數據源)
* @Author: wqc
* @Date: 2022-03-02
* @Version: V1.0
*/
@Service
public class MesProdSqlLitePqcStandardServiceImpl
extends ServiceImpl<MesProdSqlLitePqcStandardMapper, MesProdSqlLitePqcStandard>
implements IMesProdSqlLitePqcStandardService {

@Override
public List<MesProdSqlLitePqcStandard> findByPcbId(Integer pcbId) {
LambdaQueryWrapper<MesProdSqlLitePqcStandard> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MesProdSqlLitePqcStandard::getPcbId, pcbId);
return list(queryWrapper);
}

@Override
public boolean deleteAndSaveBatch(List<MesProdSqlLitePqcStandard> mesProdSqlLitePqcStandards) {
if (CollectionUtils.isEmpty(mesProdSqlLitePqcStandards)) {
return false;
}
LambdaQueryWrapper<MesProdSqlLitePqcStandard> queryWrapper = new LambdaQueryWrapper<>();
Integer pcbId = mesProdSqlLitePqcStandards.get(0).getPcbId();
queryWrapper.eq(MesProdSqlLitePqcStandard::getPcbId, mesProdSqlLitePqcStandards.get(0).getPcbId());
if (CollectionUtils.isNotEmpty(findByPcbId(pcbId))) {
if (remove(queryWrapper)) {
return saveBatch(mesProdSqlLitePqcStandards);
} else {
return false;
}
}
return saveBatch(mesProdSqlLitePqcStandards);
}
}




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM