数据库字段与java实体中的属性映射不上

数据库字段与java实体中的属性映射不上

总结:
  1. 当数据中的字段与java实体中的属性映射不上时,我们可以这样做:
    方式一:取别名
select ID id,NAME name,TB_JSON tbJson
from temp

方式二:使用<resultMap>

<resultMap id="PeopleBase" type="com.thin.hello.People">
        <id column="ID" property="id" jdbcType="VARCHAR"></id>
        <result column="NAME" property="name" jdbcType="VARCHAR"></result>
        <result column="AGE" property="age" jdbcType="VARCHAR"></result>
        <result column="SEX" property="sex" jdbcType="VARCHAR"></result>
        <result column="BIRTH" property="birth" jdbcType="VARCHAR"></result>
        <result column="UPDATEUSER" property="updateUser" jdbcType="VARCHAR"></result>
        <result column="UPDATETIME" property="updateTime" jdbcType="TIMESTAMP"></result>
 </resultMap>
<sql id="Column_People">
        ID ,NAME ,AGE ,SEX ,BIRTH ,UPDATEUSER ,UPDATETIME
</sql>

方式三:在mybatis-config.xml中添加配置信息(mapUnderscoreToCamelCase)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<settings>
		<setting name="mapUnderscoreToCamelCase" value="true" />
	</settings>
</configuration>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,为了正确映射PostgreSQL数据库的jsonb字段Java实体类应该按照以下方式进行定义: ```java @Data @NoArgsConstructor @AllArgsConstructor @Entity @Table(name = "customer_profile") @TypeDefs({ @TypeDef(name = "string-array", typeClass = StringArrayType.class), @TypeDef(name = "int-array", typeClass = IntArrayType.class), @TypeDef(name = "json", typeClass = JsonStringType.class), @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) }) public class CustomerProfile implements Serializable { @Id @GeneratedValue(strategy = SEQUENCE) private Integer id; @Column(length = 32, nullable = false) private String name; @Type(type = "jsonb") @Column(columnDefinition = "jsonb") private CustomerThemeSetting settings; @Type(type = "string-array") @Column(columnDefinition = "text\[\]") private String\[\] phones; } class CustomerThemeSetting { // ... some instance field. } ``` 在实体,使用`@Type`注解来指定字段的类型,例如`@Type(type = "jsonb")`表示该字段是jsonb类型。同时,使用`@Column(columnDefinition = "jsonb")`来指定数据库的列定义。另外,还需要在实体类上使用`@TypeDefs`注解来定义自定义类型的映射关系。 此外,为了正确使用Hibernate与PostgreSQL的jsonb数据类型,需要在项目的Maven依赖添加`hibernate-types-52`的依赖项。具体的依赖配置可以参考引用\[2\]提供的代码段。 希望这个回答能够解决你的问题。 #### 引用[.reference_title] - *1* *2* *3* [Hibernate jsonb Java Object Type Java实体字段怎么写才能正确映射?](https://blog.csdn.net/wuyujin1997/article/details/120981261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值