插入数据错误
.SQLException: Incorrect string value: ‘\xE5\x8C\x97\xE4\xBA\xAC…’ for column ‘hosname’ at row 1
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate
当我们需要插入数据的时候这个报错,查询后得知
时间格式错误
[org.springframework.context.support.DefaultMessageSourceResolvable: codes [downloadCountQueryVo.downloadDateBegin,downloadDateBegin]; arguments []; default message [downloadDateBegin]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘downloadDateBegin’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@io.swagger.annotations.ApiModelProperty java.util.Date] for value ‘2022-07-01’; nested exception is java.lang.IllegalArgumentException]
在VO类中不能设置成date要在service自己转
@Override
public void saveDownload(DownloadCountQueryVo downloadCountQueryVo) {
try {
Download download = new Download();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String hoscode = hospitalFeignClient.getHoscode(downloadCountQueryVo.getHosname());
download.setDownloadDateBegin(sdf.parse(downloadCountQueryVo.getDownloadDateBegin()));
download.setDownloadDateEnd(sdf.parse(downloadCountQueryVo.getDownloadDateEnd()));
download.setHosname(downloadCountQueryVo.getHosname());
download.setStatus(0);
download.setHoscode(hoscode);
baseMapper.insert(download);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
数据库有数据但是查不到
@Override
public void startDownload() {
//获取所有的states为未处理的
QueryWrapper<Download> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", 0);
List<Download> downloads = baseMapper.selectList(queryWrapper);
for (Download download : downloads) {
coreDownload(download);
}
}
之后尝试这样
还是不行
找到原因了因为我们用到了base实体类中的逻辑删除,所以会出现这种情况
成了,完善一下,给文件名字添加一个UUID