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;
    }
}
相关推荐
海棠一号15 分钟前
JAVA理论第五章-JVM
java·开发语言·jvm
eternal__day32 分钟前
Spring Cloud 多机部署与负载均衡实战详解
java·spring boot·后端·spring cloud·负载均衡
颜淡慕潇36 分钟前
Redis 实现分布式锁:深入剖析与最佳实践(含Java实现)
java·redis·分布式
程序员秘密基地42 分钟前
基于vscode,idea,java,html,css,vue,echart,maven,springboot,mysql数据库,在线考试系统
java·vue.js·spring boot·spring·web app
何中应43 分钟前
【设计模式-5】设计模式的总结
java·后端·设计模式
吾日三省吾码1 小时前
Spring 团队详解:AOT 缓存实践、JSpecify 空指针安全与支持策略升级
java·spring·缓存
风象南1 小时前
SpringBoot的5种日志输出规范策略
java·spring boot·后端
咖啡啡不加糖1 小时前
深入理解MySQL死锁:从原理、案例到解决方案
java·数据库·mysql
zimoyin1 小时前
Compose Multiplatform 实现自定义的系统托盘,解决托盘乱码问题
java
啾啾Fun2 小时前
【Java微服务组件】分布式协调P4-一文打通Redisson:从API实战到分布式锁核心源码剖析
java·redis·分布式·微服务·lua·redisson