Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. package com.AddressBook.spring;
  2.  
  3. import java.util.List;
  4.  
  5. import org.springframework.data.repository.CrudRepository;
  6. import org.springframework.transaction.annotation.Transactional;
  7.  
  8.  
  9. public interface ContactRepository extends CrudRepository<Contact, Long>{
  10.  
  11. @Transactional
  12. List<Contact> findBySurname(String surname);
  13.  
  14. @Transactional
  15. List<Contact> removeBySurname(String surname);
  16. }
  17.  
  18.  
  19. @RequestMapping(value = "/search", method = RequestMethod.GET)
  20. public String searchForm(Contact contact, @RequestParam (value = "surname", required = false) String surname, Model model) {
  21. return "search";
  22. }
  23. @RequestMapping(value = "/search", method = RequestMethod.POST)
  24. public String searchContact(Contact contact, @RequestParam (value = "surname", required = false) String surname, Model model) {
  25.  
  26. model.addAttribute("search", contactRep.findBySurname(surname));
  27. return "search";
  28. }
  29.  
  30.  
  31. <!DOCTYPE HTML>
  32. <html xmlns:th="http://www.thymeleaf.org">
  33. <head>
  34. <title>search contact</title>
  35. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  36. </head>
  37. <body>
  38. <h1>Search contacts:</h1>
  39. <form th:object="${contacts}" th:action="@{/search}" method="get">
  40. <input type="text" name="search" id="search" th:value="${search}"/>
  41. <input type="submit" value="Search"/>
  42. <div th:if="${not #lists.isEmpty(contacts)}">
  43. <h2>Students List</h2>
  44. <table class="table table-striped">
  45. <tr>
  46. <th>Id</th>
  47. <th>Name</th>
  48. <th>Surname</th>
  49. <th>email</th>
  50. <th>phone number:</th>
  51. </tr>
  52. <tr th:each="contact: ${contacts}">
  53. <td th:text="${contact.id}">id</td>
  54. <td th:text="${contact.name}">name</td>
  55. <td th:text="${contact.surname}">surname</td>
  56. <td th:text="${contact.email}">email</td>
  57. <td th:text="${contact.phoneNumber}">phone number</td>
  58. </tr>
  59. </table>
  60. </div>
  61. <p><a href="/add">Add another contact</a> <a href="/list">Show list
  62. of contacts</a></p>
  63. </form>
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement