2017-07-18 93 views
0

我在PostgreSQL的以下DB双引号

create table car_wash(
    id integer PK, 
    images text[] 
) 

要插入一些数据图像阵列我使用的是春天开机,这是从我的仓库接口方法

@Modifying 
    @Query(value = "update car_wash set images=array_append(images,'' || :item || '') where id =:id",nativeQuery = true) 
    void updateImage(@Param("item") String item,@Param("id")Integer id); 

但是,当我把一些字符串,如F:\eclipse\workspace\TestMail\test.txt分贝这个路径是用双引号"F:\eclipse\workspace\TestMail\test.txt" 我不知道为什么,但是当我试图删除图像aray使用此查询UPDATE car_wash SET images= array_remove(images, '"F:\eclipse\workspace\TestMail\test.txt"');一些字符串它不会被删除.W帽子是原因吗?

+0

删除不工作的原因最有可能的是双引号不是存储在数据库中的字符串。为什么字符串包含那些我不能说的双引号,特别是不知道它来自哪里。 – Thomas

+0

我只是将文件保存在远程服务器中,并执行以下操作: private void addImageToCarWash(CarWash carWash,File newImage){carwashRepository.updateImage(newImage.getAbsolutePath(),carWash.getId()); } –

+0

嗯,你可能想试试'...':item'...'。由于您使用Java构建查询,因此不需要该字符串连接。此外,请尝试调试您的代码,以查看双引号添加到字符串的位置('getAbsolutePath()'不应该这样做)。 – Thomas

回答

0

最后我找到了答案。我不知道为什么,但春天把所有的路径字符串包装成双引号,解决这个问题你应该做下面的事情carWashRepository.updateImage(newImage.getAbsolutePath().replace("\\", "/"), carWash.getId());