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

运行结果:

相关推荐
2501_937860941 小时前
MySQL表的操作:创建、查看、修改、删除完整实战
android·数据库·mysql
奇特認5 小时前
mysql 集群技术 3.高可用之 MHA
数据库·mysql
rannn_1118 小时前
【力扣hot100】链表专题|160、206、234、141、142
java·算法·leetcode·链表·面试·开发
Bioinfo Guy8 小时前
高分Panel复现系列|转录因子网络太乱?用模块框把重点圈出来
数据库·生物信息学·生信可视化
ltl9 小时前
Disaggregated DB 合集:Socrates、PolarDB、Taurus 的共同模式
数据库
IKUN家族9 小时前
Spring IoC&DI
java·spring·rpc
山荷枝11 小时前
03-框架--Spring
java·后端·spring
ChaHae-In11 小时前
SpringBoot统一功能处理
java·spring boot·后端
Blossom i11 小时前
大数据预处理与采集实验一:使用Python操作MySQL数据库
数据库·mysql
coder!mq11 小时前
说几个常见的语法糖?
java·开发语言·算法