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

运行结果:

相关推荐
whm27771 天前
Visual Basic 值传递与地址传递
java·开发语言·数据结构
倔强的石头_1 天前
金仓多模数据库平替 MongoDB:电子证照国产化的技术实操与价值突破
数据库
Go高并发架构_王工1 天前
MySQL性能优化案例分析:从问题到解决方案
数据库·mysql·性能优化
没有bug.的程序员1 天前
云原生与分布式架构的完美融合:从理论到生产实践
java·分布式·微服务·云原生·架构
村口张大爷1 天前
Spring Boot 初始化钩子
java·spring boot·后端
x_feng_x1 天前
Java从入门到精通 - 集合框架(二)
java·开发语言·windows
LB21121 天前
苍穹外卖-缓存套餐 Spring Cache day07
java·spring boot·spring
二十三之歌1 天前
Redis 中文学习手册
数据库·redis·学习
Le1Yu1 天前
雪崩问题及其解决方案(请求限流、线程隔离、服务熔断、fallback、sentinel实现以上功能)
java·开发语言
徐子童1 天前
基于微服务的在线判题系统重点总结
java·微服务·架构