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

运行结果:

相关推荐
达梦产品与服务2 小时前
SQLark V4.4 更新 | 新增 SQL Server 数据库支持、自定义格式复制、Agent 辅助建表等 20+ 项功能已上线!
数据库
小Ti客栈4 小时前
MySQL 常用函数速查(完整篇)
数据库·mysql·adb
隔窗听雨眠5 小时前
高可用不止于数据库的全栈工程实践
数据库·架构设计·高可用
Resean02236 小时前
Spring 源码分析(二)配置类的解析与扫描
java·后端·spring
小毛球.6 小时前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
Misnearch7 小时前
ScheduledExecutorService
java·线程池
nice_lcj5208 小时前
MySQL 主从复制与读写分离:从库怎么跟着主库走
数据库·mysql·面试·binlog·读写分离·主从复制
tianyuanwo8 小时前
PostgreSQL 部署运维实战总结:从安装踩坑到生产可用
运维·数据库·postgresql
ashiho8 小时前
【LeetCode hot 100】3. 无重复字符的最长子串 (三种解法)
java·数据结构·后端·算法·leetcode·滑动窗口