Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 百里香不是';t将我的控制器方法映射到html模板_Java_Spring_Spring Boot_Maven_Thymeleaf - Fatal编程技术网

Java 百里香不是';t将我的控制器方法映射到html模板

Java 百里香不是';t将我的控制器方法映射到html模板,java,spring,spring-boot,maven,thymeleaf,Java,Spring,Spring Boot,Maven,Thymeleaf,我试图在加载一个html模板时从数据库加载对象。目前,它们没有加载,并且我的控制器方法都不起作用。我不知道这是一个pom问题还是我这边的接线缺失。。。附加我的html、控制器、应用程序和pom 谢谢你的帮助 聚甲醛 更新: 当我在浏览器上加载英雄时,我得到一个“未找到文件”错误 更新: 以下是我的文件结构: 更新: 以下是我的应用程序属性,其中包含已编辑的登录信息 应用程序属性 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Dri

我试图在加载一个html模板时从数据库加载对象。目前,它们没有加载,并且我的控制器方法都不起作用。我不知道这是一个pom问题还是我这边的接线缺失。。。附加我的html、控制器、应用程序和pom

谢谢你的帮助

聚甲醛

更新:

当我在浏览器上加载英雄时,我得到一个“未找到文件”错误

更新: 以下是我的文件结构:

更新: 以下是我的应用程序属性,其中包含已编辑的登录信息

应用程序属性

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/SuperHeroDB?serverTimezone=America/Chicago&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=[redacted]
spring.datasource.password=[redacted]
spring.profiles.active=database

Thymeleaf并没有让我失望,我是直接从我的计算机访问文件,而不是在浏览器中访问localhost:8080/heros。我对http请求非常陌生,所以请原谅我在浏览器上加载/heros时会发生什么?同时向我们展示您的文件夹结构。你的html文件在哪里?@gtiwari333刚刚更新了帖子。感谢您查看应用程序中的内容。属性?@gtiwari333刚刚更新了应用程序属性下次使用start.spring.io,您就不必担心文件夹结构了much@vphilipnyc谢谢你的提示,我试试看:)
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

        <title>Heroes</title>
    </head>
    <body>
        <!-- Main Body of Page -->
        <div class="container">
            <div class="row m-4">
                <div class="col text-center border border-dark">
                    <h1><a href="/" class="text-dark">Heroes</a></h1>
                </div>
            </div>
            <div class="row m-4 border border-dark">
                <div class="col text-center m-3">
                    <a href="home.html" class="btn btn-outline-primary btn-lg">Home</a>
                </div>
                <div class="col text-center m-3">
                    <a href="students" class="btn btn-outline-primary btn-lg">Search</a>
                </div>
            </div>
            <div class="col-md-9">
                 <div id="tableDiv">

                     <table id="objectTable" class="table table-hover">

                         <tbody id="contentRows"></tbody>
                     </table>
                 </div>

             </div>


            <div class="row m-4 border border-dark">
                <div class="col-3 text-center m-3">
                    <span class="h3">Add Hero</span>
                </div>
                <div class="col-7 text-center m-3">
                    <form action="addHero" method="POST">
                        <div class="form-group row">
                            <label for="name" class="col-3 col-form-label">
                                Name</label>
                            <div class="col-9">
                                <input type="text" name="name"
                                       id="name" class="form-control"/>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="description" class="col-3 col-form-label">
                                Description</label>
                            <div class="col-9">
                                <input type="text" name="description"
                                       id="description" class="form-control"/>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="Superpower" class="col-3 col-form-label">
                                Superpower</label>
                            <div class="col-9">
                                <select id="superpower" name="superpowerId" class="form-control" >
                                    <option th:each="superpower : ${Superpowers}"
                                            th:value="${superpower.id}"
                                            th:text="${superpower.name}">
                                        Superpower</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="organizations" class="col-3 col-form-label">
                                Organizations</label>
                            <div class="col-9">
                                <select multiple id="organizations" name="organizationId"
                                        class="form-control" >
                                    <option th:each="organization : ${organizations}"
                                            th:value="${organization.id}"
                                            th:text="${organization.name}">
                                        organization</option>
                                </select>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary">Add Hero</button>
                    </form>
                </div>
            </div>

            <div class="row m-4 border border-dark">
                <div class="col text-center m-3">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                              <th>Hero</th>
                             <th>Superpower</th>
                             <th>Description</th>
                                <th>Details</th>
                                <th>Edit</th>
                                <th>Delete</th>
                            </tr>
                        </thead>
                        <tbody>
                              <tr th:each="hero : ${heroes}">
                                   <td th:text='${hero.heroName}'>Hero Name</td>
                                <td th:text="${hero.superPower}">Hero Superpower</td>
                                <td th:text="${hero.heroDescription}">Hero Description</td>
                                <td><a href="#" th:href="@{/courseDetail(id=${course.id})}">Details</a></td>
                                <td><a href="#" th:href="@{/editCourse(id=${course.id})}">Update</a></td>
                                <td><a href="#" th:href="@{/deleteCourse(id=${course.id})}">Delete</a></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- End main body -->

        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="js/jquery-2.2.4.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    </body>
</html>; 

package com.sg.SuperHeroSightings.controller;

import com.sg.SuperHeroSightings.dao.HeroDao;
import com.sg.SuperHeroSightings.dao.OrganizationDao;
import com.sg.SuperHeroSightings.dao.SuperpowerDao;
import com.sg.SuperHeroSightings.dto.Hero;
import com.sg.SuperHeroSightings.dto.Organization;
import com.sg.SuperHeroSightings.dto.Superpower;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;






/**
 *
 * @author Chelsea, Karma, Mohammed, Patrick
 */
@Controller
public class HeroController {

    @Autowired
    SuperpowerDao superpowerDao;

    @Autowired
    OrganizationDao organizationDao;

    @Autowired
    HeroDao heroDao;
    
    
    
    
 @GetMapping("/heroes")
    public String displayHeroes(Model model) {
        List<Hero> heroes = heroDao.getAllHeroes();
        List<Superpower> superpowers = superpowerDao.getAllSuperpowers();
        List<Organization> organizations = organizationDao.getAllOrganizations();

        model.addAttribute("heroes", heroes);
        model.addAttribute("superpowers", superpowers);
        model.addAttribute("organizations", organizations);

        return "heroes";
    }
package com.sg.SuperHeroSightings;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SuperHeroSightingsApplication {

    public static void main(String[] args) {
        SpringApplication.run(SuperHeroSightingsApplication.class, args);
    }

}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/SuperHeroDB?serverTimezone=America/Chicago&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=[redacted]
spring.datasource.password=[redacted]
spring.profiles.active=database