Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. @Entity
  2. public class Producto {
  3.  
  4. private Integer id;
  5. private String nombre;
  6. private List<Formato> listaFormatos;
  7.  
  8. public Producto() {
  9. }
  10.  
  11. @Id
  12. @GeneratedValue(strategy = GenerationType.AUTO)
  13. public Integer getId() {
  14. return id;
  15. }
  16.  
  17. public void setId(Integer id) {
  18. this.id = id;
  19. }
  20.  
  21. public String getNombre() {
  22. return nombre;
  23. }
  24.  
  25. public void setNombre(String nombre) {
  26. this.nombre = nombre;
  27. }
  28.  
  29. @OneToMany(mappedBy = "producto", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  30. public List<Formato> getListaFormatos() {
  31. return listaFormatos;
  32. }
  33.  
  34. public void setListaFormatos(List<Formato> listaFormatos) {
  35. this.listaFormatos = listaFormatos;
  36. }
  37. }
  38.  
  39. @Entity
  40. public class Formato {
  41.  
  42. private Integer id;
  43. private Integer cantidad;
  44. private String unidadMedida;
  45. private Producto producto;
  46.  
  47. public Formato() {
  48. }
  49.  
  50. @Id
  51. @GeneratedValue(strategy = GenerationType.AUTO)
  52. public Integer getId() {
  53. return id;
  54. }
  55.  
  56. public void setId(Integer id) {
  57. this.id = id;
  58. }
  59.  
  60. @ManyToOne
  61. @JoinColumn(name = "producto_id", referencedColumnName = "id")
  62. public Producto getProducto() {
  63. return producto;
  64. }
  65.  
  66. public void setProducto(Producto producto) {
  67. this.producto = producto;
  68. }
  69.  
  70. public Integer getCantidad() {
  71. return cantidad;
  72. }
  73.  
  74. public void setCantidad(Integer cantidad) {
  75. this.cantidad = cantidad;
  76. }
  77.  
  78. public String getUnidadMedida() {
  79. return unidadMedida;
  80. }
  81.  
  82. public void setUnidadMedida(String unidadMedida) {
  83. this.unidadMedida = unidadMedida;
  84. }
  85. }
  86.  
  87. public interface ProductoRepository extends CrudRepository<Producto, Integer> {
  88. }
  89.  
  90. spring.datasource.url = jdbc:mysql://localhost:3306/x1
  91. spring.datasource.username = x2
  92. spring.datasource.password = x3
  93. spring.jpa.show-sql=true
  94. spring.jpa.database=mysql
  95.  
  96. spring.jpa.hibernate.ddl-auto=create-drop
  97.  
  98. <dependencies>
  99. <dependency>
  100. <groupId>org.springframework.boot</groupId>
  101. <artifactId>spring-boot-starter-data-jpa</artifactId>
  102. </dependency>
  103. <dependency>
  104. <groupId>org.springframework.boot</groupId>
  105. <artifactId>spring-boot-starter-data-rest</artifactId>
  106. </dependency>
  107. <dependency>
  108. <groupId>org.springframework.boot</groupId>
  109. <artifactId>spring-boot-starter-jersey</artifactId>
  110. </dependency>
  111. <dependency>
  112. <groupId>org.springframework.boot</groupId>
  113. <artifactId>spring-boot-starter-mail</artifactId>
  114. </dependency>
  115. <dependency>
  116. <groupId>org.springframework.boot</groupId>
  117. <artifactId>spring-boot-starter-web</artifactId>
  118. </dependency>
  119. <dependency>
  120. <groupId>mysql</groupId>
  121. <artifactId>mysql-connector-java</artifactId>
  122. <scope>runtime</scope>
  123. </dependency>
  124. <dependency>
  125. <groupId>org.springframework.boot</groupId>
  126. <artifactId>spring-boot-starter-tomcat</artifactId>
  127. <scope>provided</scope>
  128. </dependency>
  129. <dependency>
  130. <groupId>org.springframework.boot</groupId>
  131. <artifactId>spring-boot-starter-test</artifactId>
  132. <scope>test</scope>
  133. </dependency>
  134. <dependency>
  135. <groupId>org.springframework.boot</groupId>
  136. <artifactId>spring-boot-devtools</artifactId>
  137. <optional>true</optional>
  138. </dependency>
  139. </dependencies>
  140.  
  141. {"nombre": "x",
  142. "listaFormatos": [
  143. {"cantidad": 1,
  144. "unidadMedida":"kg"},
  145. {"cantidad": 2,
  146. "unidadMedida":"g"}
  147. ]
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement