使用@Column获取数据库字段属性,数据库里面有值,但是转换成驼峰后变成null

发布于 2022-09-12 23:53:10 字数 4568 浏览 19 评论 0

可以获取到rental_number的值,但是update_time, create_time, image_path都获取不到

TenantMessageMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.spring.inter.mapper.Mapper.TenantMessageMapper">

    <sql id="Base_Column_List">
      id, title, userID, rental, address, update_time, create_time,
      rental_number, image_path
    </sql>

    <select id="getAll" resultType="TenantMessage">
        SELECT <include refid="Base_Column_List" />
        FROM tenant_message
        <choose>
            <when test="sort=='asc'">
                ORDER by id ASC limit #{start}, #{dataLength}
            </when>
            <otherwise>
                ORDER by id DESC limit #{start}, #{dataLength}
            </otherwise>
        </choose>
    </select>

    <select id="getCount" resultType="java.lang.Integer">
        SELECT count(id) FROM tenant_message
    </select>
</mapper>

TenantMessage.java

package cn.spring.inter.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

@Entity
@Table(name = "tenant_message")
public class TenantMessage {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "title")
    private String title;

    @Column(name = "userID")
    private Integer userID;

    @Column(name = "rental")
    private String rental;

    @Column(name = "address")
    private String address;

    @Column(name = "update_time")
    private String updateTime;

    @Column(name = "create_time")
    private String createTime;

    @Column(name = "rental_number")
    private int rentalNumber;

    @Column(name = "image_path")
    private String imagePath;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getUserID() {
        return userID;
    }

    public void setUserID(Integer userID) {
        this.userID = userID;
    }

    public String getRental() {
        return rental;
    }

    public void setRental(String rental) {
        this.rental = rental;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public int getRentalNumber() {
        return rentalNumber;
    }

    public void setRentalNumber(int rentalNumber) {
        this.rentalNumber = rentalNumber;
    }

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    @Override
    public String toString() {
        return "TenantMessage={id=" + this.id + ", " +
                "title=" + this.title +"}" ;
    }
}

application.properties

# 补充配置
spring.datasource.type = com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime= 500000 
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1

# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腻橙味 2022-09-19 23:53:10

一般来说mybatis配置好后会支持对数据库的_下划线与小驼峰的映射
如 user_info -> userInfo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文