Merge pull request #4 from jordanmason-stleo/master
Updates from Jordan
This commit is contained in:
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "mvn exec:java",
|
||||
"name": "Run mvn exec",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
},
|
||||
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Launch) - Current File",
|
||||
"request": "launch",
|
||||
"mainClass": "${file}"
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
]
|
||||
}
|
||||
10
pom.xml
10
pom.xml
@ -20,6 +20,8 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<spring.version>3.2.2.RELEASE</spring.version>
|
||||
<jstl.version>1.2</jstl.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -31,7 +33,15 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- jstl -->
|
||||
<dependency>
|
||||
<groupId>jstl</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>${jstl.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Core -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@ -55,6 +55,46 @@ public class SQLDriver {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Card> getAllCards() {
|
||||
ArrayList<Card> topdeck = new ArrayList<Card>();
|
||||
try {
|
||||
c = DriverManager.getConnection("jdbc:sqlite:cards.db");
|
||||
c.setAutoCommit(false);
|
||||
|
||||
Statement stmt = c.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM CARDS;");
|
||||
String cardName = "";
|
||||
int manaCost = 0;
|
||||
int power = 0;
|
||||
int toughness = 0;
|
||||
String description = "";
|
||||
String image = "";
|
||||
String creatureType = "";
|
||||
|
||||
while (rs.next()) {
|
||||
cardName = rs.getString("CARDNAME");
|
||||
manaCost = rs.getInt("MANACOST");
|
||||
power = rs.getInt("POWER");
|
||||
toughness = rs.getInt("TOUGHNESS");
|
||||
description = rs.getString("DESCRIPTION");
|
||||
image = rs.getString("IMAGE");
|
||||
creatureType = rs.getString("CREATURETYPE");
|
||||
Card card = new Card(cardName, manaCost, power, toughness, description, image, creatureType);
|
||||
topdeck.add(card);
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
c.close();
|
||||
|
||||
return topdeck;
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
System.err.println("Returning null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean insertCard(Card card) {
|
||||
Statement stmt = null;
|
||||
try {
|
||||
|
||||
34
src/main/java/MTGClone/controller/CardController.java
Normal file
34
src/main/java/MTGClone/controller/CardController.java
Normal file
@ -0,0 +1,34 @@
|
||||
package MTGClone.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import MTGClone.Card;
|
||||
import MTGClone.SQLDriver;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Controller
|
||||
public class CardController {
|
||||
@GetMapping({"/card"})
|
||||
public String hello(Model model) {
|
||||
ArrayList<Card> allCards = (new SQLDriver()).getAllCards();
|
||||
model.addAttribute("allcards", allCards);
|
||||
|
||||
return "card";
|
||||
}
|
||||
|
||||
@PostMapping({"/card"})
|
||||
public String greet(@RequestParam("cardname") String cardname, @RequestParam("manacost") int manacost,
|
||||
@RequestParam("power") int power, @RequestParam("toughness") int toughness, @RequestParam("description") String description, @RequestParam("creaturetype") String creaturetype,
|
||||
ModelMap modelMap) {
|
||||
Card newCard = new Card(cardname, manacost, power, toughness, description, "", creaturetype);
|
||||
SQLDriver d = new SQLDriver();
|
||||
d.insertCard(newCard);
|
||||
return "card";
|
||||
}
|
||||
|
||||
}
|
||||
67
src/main/webapp/WEB-INF/jsp/card.jsp
Normal file
67
src/main/webapp/WEB-INF/jsp/card.jsp
Normal file
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<style>
|
||||
.container {
|
||||
width: 350px;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.container input {
|
||||
width: 100%;
|
||||
clear: both;
|
||||
|
||||
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello ${name}!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2 class="hello-title">Hello ${name}!</h2>
|
||||
<div class="container">
|
||||
|
||||
<form action="/card" method="post">
|
||||
<label for="cardname">Card Name:</label>
|
||||
<input type="text" id="cardname" name="cardname"><br>
|
||||
<label for="manacost">Mana Cost:</label>
|
||||
<input type="text" id="manacost" name="manacost"><br>
|
||||
<label for="power">Power:</label>
|
||||
<input type="text" id="power" name="power"><br>
|
||||
<label for="toughness">Toughness:</label>
|
||||
<input type="text" id="toughness" name="toughness"><br>
|
||||
<label for="description">Description:</label>
|
||||
<input type="text" id="description" name="description"><br>
|
||||
<label for="creaturetype">Creature Type:</label>
|
||||
<input type="text" id="creaturetype" name="creaturetype"><br>
|
||||
<br> <input style="width:30%;display:block;margin:0 auto;" type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
<th>Card Name</th>
|
||||
<th>Mana Cost</th>
|
||||
<th>Power</th>
|
||||
<th>Toughness</th>
|
||||
<th>Description</th>
|
||||
<th>Creature Type</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<c:if test="${not empty allcards}">
|
||||
|
||||
<c:forEach var="listValue" items="${allcards}">
|
||||
<td>${listValue.cardName}</td>
|
||||
<td>${listValue.manaCost}</td>
|
||||
<td>${listValue.power}</td>
|
||||
<td>${listValue.toughness}</td>
|
||||
<td>${listValue.description}</td>
|
||||
<td>${listValue.creatureType}</td>
|
||||
</c:forEach>
|
||||
|
||||
</c:if>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user