Skip to content

Commit

Permalink
Setup Spring Loaded, and add BookController
Browse files Browse the repository at this point in the history
  • Loading branch information
keik committed Dec 18, 2014
1 parent 50ee3e3 commit 20a1f1a
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

MAVEN_OPTS="-javaagent:springloaded-1.2.1.RELEASE.jar -noverify" mvn spring-boot:run
Binary file added springloaded-1.2.1.RELEASE.jar
Binary file not shown.
58 changes: 58 additions & 0 deletions src/main/java/spring_boot_tutorial/controller/BookController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package spring_boot_tutorial.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/books")
public class BookController {

@RequestMapping(method = RequestMethod.GET)
public String index(Model model) {
List<String> books = Arrays.asList("foo", "bar", "foobar");
model.addAttribute("books", books);
return "book-index";
}

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String show() {
// TODO
return null;
}

@RequestMapping(value = "/new", method = RequestMethod.GET)
public String new_() {
// TODO
return null;
}

@RequestMapping(method = RequestMethod.POST)
public String create() {
// TODO
return null;
}

@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit() {
// TODO
return null;
}

@RequestMapping(method = RequestMethod.PUT)
public String update() {
// TODO
return null;
}

@RequestMapping(method = RequestMethod.DELETE)
public String destroy() {
// TODO
return null;
}

}
44 changes: 44 additions & 0 deletions src/main/resources/templates/book-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
table {border: 1px solid #ccc; border-collapse: collapse}
th, td {border: 1px solid #ccc; padding: 8px;}
</style>
</head>
<body>

<h1>All books</h1>

<table>
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
</tr>
</thead>
<tbody th:remove="all-but-first">
<tr th:each="book, itr : ${books}">
<td th:text="${itr.index} + 1">1</td>
<td th:text="${book}">book1</td>
<td th:text="TODO">author1</td>
<td th:text="TODO">publisher1</td>
</tr>
<tr>
<td>2</td>
<td>book2</td>
<td>author2</td>
<td>publisher2</td>
</tr>
</tbody>
</table>

</body>
</html>

0 comments on commit 20a1f1a

Please sign in to comment.