问题描述
- 在java中怎么处理才能将数据存入postgresql数据库中类型为hstore的字段?
-
/*** 增加批量导入映射. * * @param * @return */ @Action(value = "addImportMapper", results = { @Result(name = "addImportMapper", type = "json", params = { "root", "jsonResult" }) }) public String addImportMapper() { Boolean operateResult = getImportMapperService().addImportMapper( assembleParameterToAddImportMapper()); Map<String, Object> map = new HashMap<String, Object>(); map.put("result", operateResult); jsonResult = map; return "addImportMapper"; } /** * 由于是对外提供接口,不宜显式地暴露对象. <br/> * 故将参数组装成对象. * * @return */ @SuppressWarnings("unchecked") private ImportMapper assembleParameterToAddImportMapper() { ImportMapper importMapper = new ImportMapper(); importMapper.setUuid(UUIDGenerator.genUuidStr()); importMapper.setMapperName("教职工姓名"); importMapper.setMatchedOrgUuid("123456"); importMapper.setMapperRule("name=>name,age=>20"); //hstore类型 importMapper.setCreatorUuid("789456"); return importMapper; }
<insert id="insertImportMapper" parameterType="net.firstelite.bicp.dtd.personnel$manage.system.ImportMapper"> insert into t_pm_sys_import_mapper ( uuid, mapper_name, matched_org_uuid, mapper_rule, creator_uuid, create_time, modify_time )values( #{uuid}, #{mapperName}, #{matchedOrgUuid}, #{mapperRule}, #{creatorUuid}, current_timestamp(0), current_timestamp(0) ) </insert>
解决方案
XXXMapper.xml里面的配置为如下
insert into hstore_tb(key_value) values(#{key_value}::hstore);
解决方案三:
importMapper.setMapperRule("name=>name,age=>20"); 这样写是字符串类型
hstore h=new hstore("name=>name,age=>20")像这样弄把---这个按自己猜想的,不知这个类型怎么定义
importMapper.setMapperRule(h)
时间: 2025-01-04 06:25:08