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

运行结果:

相关推荐
哞哞不熬夜9 分钟前
JavaEE--初识网络
java·网络·java-ee
等等54322 分钟前
Java EE初阶——wait 和 notify
java·开发语言
betazhou27 分钟前
基于Linux环境实现Oracle goldengate远程抽取MySQL同步数据到MySQL
linux·数据库·mysql·oracle·ogg
API小爬虫42 分钟前
淘宝按图搜索商品(拍立淘)Java 爬虫实战指南
java·爬虫·图搜索算法
lyrhhhhhhhh1 小时前
Spring 框架 JDBC 模板技术详解
java·数据库·spring
亚林瓜子2 小时前
AWS Elastic Beanstalk控制台部署Spring极简工程
java·spring·云计算·aws·eb
2401_cf2 小时前
如何创建maven项目
java·maven·intellij-idea
喝醉的小喵2 小时前
【mysql】并发 Insert 的死锁问题 第二弹
数据库·后端·mysql·死锁
付出不多3 小时前
Linux——mysql主从复制与读写分离
数据库·mysql
初次见面我叫泰隆3 小时前
MySQL——1、数据库基础
数据库·adb