在项目中遇到需要保存照片uuid到数据库,由于可能传入多张照片,所以接收到的form定义为
@ApiModelProperty(value = "现场图片")
private List<String> pictureList;
将form转换为requesrt,两个类中的属性类型应该是一致的
在数据库保存时,保存为string字符串,
<update id="updateHandleByUuid" >
update ihorn_device_alarm_work_order
set
handle_status = #{handleStatus},
handle_time = #{handleTime},
handle_content = #{handleContent},
handle_result = #{handleResult},
handler_picture =#{pictureList},
`handler` = #{handler}
where
uuid = #{uuid}
</update>
由于mapper中和转换时在获取值的时候调取的都是get方法,因此,只需要重写相关对象的get方法即可
同样的,在查询时,查询到的值是string,返回前端的需要是一个uuid的list,将查询到的IhornDeviceAlarmWorkOrder内容转换成vo对象,
//转换list为string
public String getPictureList() {
return String.join(",",pictureList);
}
//转换string为list
public List<String> getPictureList() {
String str[] = this.pictureList.split(",");
System.out.println(str);
return Arrays.asList(str);
}