striverLily
流水会知音
采纳率50%
2015-07-17 03:40 阅读 3.7k
已采纳

在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>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    striverLily 流水会知音 2015-07-22 00:57

    XXXMapper.xml里面的配置为如下

    insert into hstore_tb(key_value) values(#{key_value}::hstore);

    点赞 评论 复制链接分享
  • strutce 丵鹰 2015-07-17 14:38

    importMapper.setMapperRule("name=>name,age=>20"); 这样写是字符串类型
    hstore h=new hstore("name=>name,age=>20")像这样弄把---这个按自己猜想的,不知这个类型怎么定义
    importMapper.setMapperRule(h)

    点赞 评论 复制链接分享
  • striverLily 流水会知音 2015-07-18 03:06

    图片说明

    点赞 评论 复制链接分享

相关推荐