Guest User

Untitled

a guest
Mar 29th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. package com.example.entities;
  2.  
  3. import java.io.Serializable;
  4.  
  5. import javax.persistence.Column;
  6. import javax.persistence.Entity;
  7. import javax.persistence.GeneratedValue;
  8. import javax.persistence.Id;
  9.  
  10. @SuppressWarnings("serial")
  11. @Entity
  12. public class Personne implements Serializable {
  13.  
  14. @Id
  15. @GeneratedValue
  16. private Long id;
  17. @Column(length = 80, name = "NOM")
  18. private String nom;
  19. @Column(length = 80, name = "PRENOM")
  20. private String prenom;
  21. @Column(length = 80, name = "ADRESSE")
  22. private String adresse;
  23. @Column(length = 80, name = "EMAIL")
  24. private String email;
  25. @Column(length = 80, name = "TELEPHONE")
  26. private String telephone;
  27.  
  28. public Long getId() {
  29. return id;
  30. }
  31.  
  32. public void setId(Long id) {
  33. this.id = id;
  34. }
  35.  
  36. public String getNom() {
  37. return nom;
  38. }
  39.  
  40. public void setNom(String nom) {
  41. this.nom = nom;
  42. }
  43.  
  44. public String getPrenom() {
  45. return prenom;
  46. }
  47.  
  48. public void setPrenom(String prenom) {
  49. this.prenom = prenom;
  50. }
  51.  
  52. public String getAdresse() {
  53. return adresse;
  54. }
  55.  
  56. public void setAdresse(String adresse) {
  57. this.adresse = adresse;
  58. }
  59.  
  60. public String getEmail() {
  61. return email;
  62. }
  63.  
  64. public void setEmail(String email) {
  65. this.email = email;
  66. }
  67.  
  68. public String getTelephone() {
  69. return telephone;
  70. }
  71.  
  72. public void setTelephone(String telephone) {
  73. this.telephone = telephone;
  74. }
  75.  
  76. public Personne() {
  77. super();
  78. }
  79. }
  80.  
  81. package com.example.repositories;
  82.  
  83. import org.springframework.data.jpa.repository.JpaRepository;
  84.  
  85.  
  86. import com.example.entities.Personne;
  87.  
  88. public interface IPersonneRepository extends JpaRepository<Personne, Long> {
  89.  
  90. }
  91.  
  92. import org.springframework.beans.factory.annotation.Autowired;
  93. import org.springframework.web.bind.annotation.DeleteMapping;
  94. import org.springframework.web.bind.annotation.GetMapping;
  95. import org.springframework.web.bind.annotation.PostMapping;
  96. import org.springframework.web.bind.annotation.PutMapping;
  97. import org.springframework.web.bind.annotation.RequestBody;
  98. import org.springframework.web.bind.annotation.RequestMapping;
  99. import org.springframework.web.bind.annotation.RestController;
  100.  
  101. import com.example.entities.Personne;
  102. import com.example.repositories.IPersonneRepository;
  103.  
  104. @RestController
  105. @RequestMapping(value = "/personne")
  106. public class PersonController {
  107.  
  108. @Autowired
  109. private IPersonneRepository iPersonneRepository;
  110.  
  111. @PostMapping(value = "/create")
  112. public Personne createPersonne(@RequestBody Personne personne) {
  113. return iPersonneRepository.save(personne);
  114. }
  115.  
  116. @PutMapping(value = "/update/{id}")
  117. public Personne updatePersonne(@PathParam(value = "id") Long id,
  118. @RequestBody Personne personne) {
  119. if (id != null) {
  120. Personne p = iPersonneRepository.findOne(id);
  121. if (p != null) {
  122. iPersonneRepository.save(personne);
  123. }
  124. }
  125. return personne;
  126. }
  127.  
  128. @DeleteMapping(value = "/delete/{id}")
  129. public void delete(@PathParam(value = "id") Long id) {
  130. if (id != null) {
  131. Personne p = iPersonneRepository.findOne(id);
  132. if (p != null) {
  133. iPersonneRepository.delete(p);
  134. }
  135. }
  136. }
  137.  
  138. @GetMapping(value = "/all")
  139. public List<Personne> allPerson() {
  140. return iPersonneRepository.findAll();
  141. }
  142.  
  143. @GetMapping(value = "/per/{id}")
  144. public Personne getOne(@PathParam(value = "id") Long id) {
  145. if (id != null) {
  146. Personne p = iPersonneRepository.findOne(id);
  147. return p;
  148. }
  149.  
  150. }
  151. }
  152.  
  153. spring.datasource.url = jdbc:mysql://localhost:3306/spring_boot_DB?
  154. createDatabaseIfNotExist=true
  155. spring.datasource.username=root
  156. spring.datasource.password=
  157. spring.datasource.driverClassName = com.mysql.jdbc.Driver
  158. spring.jpa.database=MYSQL
  159. spring.jpa.show-sql = true
  160. spring.jpa.hibernate.ddl-auto = update
  161. spring.jpa.hibernate.naming-
  162. strategy=org.hibernate.cfg.ImprovedNamingStrategy
  163. spring.jpa.properties.hibernate.dialect =
  164. org.hibernate.dialect.MySQL5Dialect
  165. server.port=8081
Add Comment
Please, Sign In to add comment