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;
    }
}
相关推荐
柚个朵朵40 分钟前
Spring的Validation,这是一套基于注解的权限校验框架
java·后端·spring
2301_8035545242 分钟前
c++和c的不同
java·c语言·c++
意倾城1 小时前
JVM内存模型
java·jvm
普通的冒险者1 小时前
几个简单的数组小练习(适合初学)
java·数据结构
keke101 小时前
Java【10_1】用户注册登录(面向过程与面向对象)
java·python·intellij-idea
程序员buddha1 小时前
Spring & Spring Boot 常用注解整理
java·spring boot·spring
C_V_Better2 小时前
Java Spring Boot 控制器中处理用户数据详解
java·开发语言·spring boot·后端·spring
胡子洲2 小时前
Spring Boot 应用中实现基本的 SSE 功能
java·spring boot·后端
t198751282 小时前
基于Qt的OSG三维建模
java·开发语言
SoFlu软件机器人2 小时前
Java 框架配置自动化:告别冗长的 XML 与 YAML 文件
xml·java·自动化