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

运行结果:

相关推荐
SimonKing2 分钟前
吊打面试官系列:Spring为什么不推荐使用字段依赖注入?
java·后端·架构
@大嘴巴子7 分钟前
MySQL知识回顾总结----数据库基础
数据库·mysql
lubiii_7 分钟前
SQL手工测试(MySQL数据库)
数据库·mysql·web安全·网络安全
魔镜魔镜_谁是世界上最漂亮的小仙女9 分钟前
java-集合
java·后端·程序员
真实的菜10 分钟前
消息队列高级特性与原理:解锁分布式系统的底层逻辑
java
若水不如远方12 分钟前
java范型
java
凌辰揽月14 分钟前
Web后端基础(基础知识)
java·开发语言·前端·数据库·学习·算法
想你依然心痛19 分钟前
数据库入门:从原理到应用
数据库
lifallen20 分钟前
深入浅出 Arrays.sort(DualPivotQuicksort):如何结合快排、归并、堆排序和插入排序
java·开发语言·数据结构·算法·排序算法
长安不见22 分钟前
背景知识: 理解LimitLatch背后的AQS
java