IDEA运行thymeleaf的html文件打开端口为63342且连不上数据库

这边贴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="apple : ${apple}">
        <td th:text="${apple.number}"></td>
        <td th:text="${apple.price}"></td>
    </tr>
</table>
</body>
</html>

运行效果这样

也没有报错,就是没法展现数据库内容,这边问题为不要在html界面直接运行

先运行项目创建时自带的AppleDashboardApplication,项目启动后,也就执行了其他的类,开启了服务器8080端口

总结一下:直接运行html文件就没有执行运行其他类的一个过程,因此要先运行总的AppleDashboardApplication,再根据controller包内部指定的RequestMapping跳转到具体页面

这边放一下controller包内代码

复制代码
package com.appledashboard.controller;

import com.appledashboard.po.Apple;
import com.appledashboard.service.AppleServicesImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@Controller
public class AppleController {
    @Autowired
    AppleServicesImpl appleServicesImpl;

    @RequestMapping("/apple")
    public String apple(Model model){
        List<Apple> apple = appleServicesImpl.queryAll();
        model.addAttribute("apple", apple);
        return "apple";
    }
}

运行结果:

相关推荐
lkbhua莱克瓦249 分钟前
Java基础——集合进阶3
java·开发语言·笔记
蓝-萧20 分钟前
使用Docker构建Node.js应用的详细指南
java·后端
l1t20 分钟前
利用DeepSeek改写SQLite版本的二进制位数独求解SQL
数据库·人工智能·sql·sqlite
多喝开水少熬夜29 分钟前
Trie树相关算法题java实现
java·开发语言·算法
QT 小鲜肉31 分钟前
【QT/C++】Qt定时器QTimer类的实现方法详解(超详细)
开发语言·数据库·c++·笔记·qt·学习
研究司马懿38 分钟前
【ETCD】ETCD常用命令
网络·数据库·云原生·oracle·自动化·运维开发·etcd
lkbhua莱克瓦241 小时前
Java基础——集合进阶用到的数据结构知识点1
java·数据结构·笔记·github
刘一说2 小时前
深入理解 Spring Boot 中的数据库迁移:Flyway 与 Liquibase 实战指南
数据库·spring boot·oracle
音符犹如代码2 小时前
Java并发List实战:CopyOnWriteArrayList原理与ArrayList常见面试题
java·开发语言·面试·list
代码or搬砖2 小时前
Docker 部署 Java 项目实践
java·docker·容器