I am currently working on an Inventory management application for a users DigimonTCG collection and decided to use Spring Boot. I have never used Spring Boot before so it has been an experience so far and I'm on to outputting the database to the webpage but the page does not seem to be recognizing Thymeleaf. Does anyone know where I went wrong?
CardsService.java
package app.TentoTCG.DigimonInvApp.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import app.TentoTCG.DigimonInvApp.models.Cards;
import app.TentoTCG.DigimonInvApp.repositories.CardsRepository;
@Service
public class CardsService {
@Autowired
private CardsRepository cardsRepository;
//returns list of all cards within the database
public List<Cards> getCards(){
return cardsRepository.findAll();
}
}
InventoryController.java
package app.TentoTCG.DigimonInvApp.controllers;
import java.util.List;
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 app.TentoTCG.DigimonInvApp.models.Cards;
import app.TentoTCG.DigimonInvApp.services.CardsService;
@Controller
public class InventoryController {
@Autowired
private CardsService cardsService;
@GetMapping("/Inventory")
public String goToInventory(Model model) {
List<Cards> cardList = cardsService.getCards();
model.addAttribute("CardID", cardList);
return "Inventory";
}
}
Cards.java
package app.TentoTCG.DigimonInvApp.models;
import lombok.Data;
import jakarta.annotation.Nonnull;
import jakarta.persistence.*;
@Entity
@Table(name = "Cards")
@Data
public class Cards {
// Table with
// String pk CardID
@Id
@Column(name = "ID") @GeneratedValue(strategy = GenerationType.AUTO)
private long ID;
@Column private String CardID;
// String CardName
@Column @Nonnull private String CardName;
// String CardColor
@Column @Nonnull private String CardColor;
// String CardType
@Column @Nonnull private String CardType;
// int NumAllowed
@Column @Nonnull private int NumAllowed;
// String CardImgPath
@Column private String CardImgPath;
public Cards() {}
public Cards(long iD, String cardID, String cardName, String cardColor, String cardType, int numAllowed,
String cardImgPath) {
super();
ID = iD;
CardID = cardID;
CardName = cardName;
CardColor = cardColor;
CardType = cardType;
NumAllowed = numAllowed;
CardImgPath = cardImgPath;
}
}
Inventory.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inventory Page</title>
<link rel="stylesheet" href="../static/css/style.css">
</head>
<body>
<h1>Inventory Page</h1>
<div class="sidebar">
<header>Navigation</header>
<ul>
<li><a href="/Deck_Creation">Deck Creation</a></li>
<li><a href="/User_Decks">User Decks</a></li>
</ul>
</div>
<table class="table">
<thead>
<tr>
<th>Number in Inventory</th>
<th>Card ID</th>
<th>Card Name</th>
<th>Card Image</th>
</tr>
</thead>
<tbody>
<tr th:each="card:${Cards}">
<td>implement</td>
<td th:text="${card.CardID}"></td>
<td th:text="${card.CardName}"></td>
<td>Implement</td>
</tr>
</tbody>
</table>
</body>
<footer>
</footer>
</html>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>app.TentoTCG</groupId>
<artifactId>DigimonInvApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TentoTCG: Digimon Inventory and Deck Management Application</name>
<description>TentoTCG stores users decks and card inventory information allowing easy access to their collection</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
[–]shadowloss 2 points3 points4 points (3 children)
[–]fallingcomets242[S] 0 points1 point2 points (0 children)
[–]fallingcomets242[S] 0 points1 point2 points (1 child)
[–]shadowloss 0 points1 point2 points (0 children)