- 进行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);
}
}