2
This commit is contained in:
1 parent
dbe4be7dd5
commit
6bdf17d0f3
7 files changed
+124
No files matched your search
Generated
+15
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GitToolBoxProjectSettings">
|
||||||
|
<option name="commitMessageIssueKeyValidationOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="commitMessageValidationEnabledOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -57,6 +57,12 @@
|
|||||||
<version>4.0.1</version>
|
<version>4.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.30</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.example.controllers;
|
||||||
|
|
||||||
|
import org.example.dao.PersonDAO;
|
||||||
|
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.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/people")
|
||||||
|
public class PeopleController {
|
||||||
|
|
||||||
|
private final PersonDAO personDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PeopleController(PersonDAO personDAO) {
|
||||||
|
this.personDAO = personDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public String index(Model model) {
|
||||||
|
model.addAttribute("people",personDAO.index());
|
||||||
|
return "people/index";
|
||||||
|
}
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public String show(@PathVariable("id") int id, Model model) {
|
||||||
|
model.addAttribute("person",personDAO.show(id));
|
||||||
|
return "people/show";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.example.dao;
|
||||||
|
|
||||||
|
import org.example.models.Person;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PersonDAO {
|
||||||
|
private final List<Person> people = new ArrayList<Person>();
|
||||||
|
{
|
||||||
|
people.add(new Person("MAO",1));
|
||||||
|
people.add(new Person("Sanders", people.size()+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Person> index() {
|
||||||
|
return people;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person show(int id) {
|
||||||
|
return people.stream().filter(person -> person.getId() == id).findAny().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.example.models;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
private String name;
|
||||||
|
private int id;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org" lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="ISO-8859-1">
|
||||||
|
<title>people</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Hello world!</p>
|
||||||
|
|
||||||
|
|
||||||
|
<div th:each="person : ${people}">
|
||||||
|
<a th:href="@{/people/{id}(id=${person.getId()})}" th:text="${person.getName()}">user</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org" lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="ISO-8859-1">
|
||||||
|
<title>Person</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p th:text="${person.getId()}"> </p>
|
||||||
|
<p th:text="${person.getName()}"> </p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in new issue
Block a user