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";
    }
}

运行结果:

相关推荐
kse_music13 分钟前
如何选择开源向量数据库
数据库·开源·向量数据库
崖山数据库系统YashanDB14 分钟前
YashanDB归档管理
数据库
Forget the Dream1 小时前
设计模式之迭代器模式
java·c++·设计模式·迭代器模式
大丈夫在世当日食一鲲1 小时前
Java中用到的设计模式
java·开发语言·设计模式
涛思数据(TDengine)1 小时前
taosd 写入与查询场景下压缩解压及加密解密的 CPU 占用分析
大数据·数据库·时序数据库·tdengine
A-Kamen1 小时前
Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现与实战指南
java·spring boot·后端
练川1 小时前
Stream特性(踩坑):惰性执行、不修改原始数据源
java·stream
狂奔小菜鸡1 小时前
Java运行时数据区
java·jvm·后端
嗨起飞了1 小时前
MySQL入门手册
数据库·mysql
trymoLiu1 小时前
SpringBoot 实现 RSA+AES 自动接口解密!
java·spring boot