IDEA前端thymeleaf只显示部分数据库问题

只显示int类型的number,不显示string类型的price和weight

先看一下apple.html

复制代码
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>User List</title>
</head>
<body>
<h1>User List</h1>

<table>
    <tr>
        <th>ID</th>
        <th>Name</th>
    </tr>
    <tr th:each="item: ${apple}">
        number: <td th:text="${item.number}"></td>
        price: <td th:text="${item.price}"></td>
        weight: <td th:text="${item.weight}"></td>
    </tr>
</table>
</body>
</html>

再在IDEA中验证下是否能查询

可以查询到,那么就是po.Apple的类型设置错误

复制代码
package com.appledashboard.po;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor

public class Apple {
    @Getter
    private Integer number;
    private String price;
    private String weight;
    public void setNumber(Integer number) {
        this.number = number;
    }

    public void setPrice(String price) {
    //错误: return price
        this.price = price;
    }

    public void setWeight(String weight) {
     //错误: return weight
        this.weight = weight;
    }
}
相关推荐
To Be Clean Coder8 分钟前
【Spring源码】createBean如何寻找构造器(四)——类型转换与匹配权重
java·后端·spring
-孤存-20 分钟前
SpringBoot核心注解与配置详解
java·spring boot·后端
Hx_Ma1634 分钟前
BCrypt
java
We....35 分钟前
鸿蒙与Java跨平台Socket通信实战
java·服务器·tcp/ip·arkts·鸿蒙
笃行客从不躺平38 分钟前
Token 复习
java·分布式·spring cloud
Albert Edison1 小时前
【Python】函数
java·linux·python·pip
2301_818732061 小时前
项目启动报错,错误指向xml 已解决
xml·java·数据库·后端·springboot
码农阿豪2 小时前
Oracle 到金仓数据库迁移实战:一次真正“落地”的国产替代之旅
java·数据库·oracle
小王不爱笑1322 小时前
SpringBoot 整合 Ollama + 本地 DeepSeek 模型
java·spring boot·后端
毕设源码-钟学长2 小时前
【开题答辩全过程】以 高校宿舍分配系统设计与实现为例,包含答辩的问题和答案
java