JAVA+mybatis+postgreSql,PATH类型数据的插入
postgre数据库中,geom为PATH类型的数据
新建实体类如下(只展示相关的属性信息)
![](https://img-blog.csdnimg.cn/direct/358c7b6824fe46a680b216c6b0b9546d.png#pic_center)
其中,geomStr字段是用于接收特殊类型数据的字符型数据的
如((1,2),(3,4))
geom是真正需要入库的字段信息
![](https://img-blog.csdnimg.cn/direct/62750df2552d4212983d7854d074b98e.png#pic_center)
在属性的set/get方法上,做处理
在geomStr的set方法中,同时对geom属性进行处理
主要就是以下的代码
try {
this.geomStr = geomStr;
PGobject pGobject = new PGobject();
pGobject.setType("path");
pGobject.setValue(geomStr);
this.geom = pGobject;
}catch (Exception e){
e.printStackTrace();
}
使用PGobject去接收真正需要处理的数据信息
其中
pGobject.setType(“path”); // 设置数据的类型
pGobject.setValue(geomStr);// 设置真正的数据信息
正常使用mybatis进行数据的新增即可