Guest User

Untitled

a guest
Apr 6th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. spring.datasource.url=jdbc:mysql://localhost:3306/springbootfirstapp
  2. spring.datasource.username=root
  3. spring.datasource.password=
  4. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  5. spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
  6. spring.jpa.hibernate.ddl-auto=update
  7.  
  8. package springbootfirstapp.controller;
  9.  
  10. import java.util.List;
  11.  
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import org.springframework.web.bind.annotation.RestController;
  16.  
  17. import springbootfirstapp.domain.Customer;
  18. import springbootfirstapp.repo.CustomerRepo;
  19.  
  20. @RestController
  21. @RequestMapping("/customer")
  22. public class CustomerController {
  23.  
  24.  
  25. @Autowired
  26. CustomerRepo rp;
  27.  
  28. @RequestMapping("/findall")
  29. @ResponseBody
  30. public List<Customer> findall(){
  31. return rp.findAll();
  32. }
  33.  
  34.  
  35.  
  36. }
  37.  
  38. package springbootfirstapp.domain;
  39.  
  40. import javax.persistence.Entity;
  41. import javax.persistence.GeneratedValue;
  42. import javax.persistence.GenerationType;
  43. import javax.persistence.Id;
  44.  
  45. @Entity
  46. public class Customer {
  47. @Id
  48. @GeneratedValue(strategy = GenerationType.AUTO)
  49. private int id;
  50. private String name;
  51. private int phone;
  52. public int getId() {
  53. return id;
  54. }
  55. public void setId(int id) {
  56. this.id = id;
  57. }
  58. public String getName() {
  59. return name;
  60. }
  61. public void setName(String name) {
  62. this.name = name;
  63. }
  64. public int getPhone() {
  65. return phone;
  66. }
  67. public void setPhone(int phone) {
  68. this.phone = phone;
  69. }
  70. public Customer(int id, String name, int phone) {
  71. super();
  72. this.id = id;
  73. this.name = name;
  74. this.phone = phone;
  75. }
  76. public Customer() {
  77. super();
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. }
  85.  
  86. package springbootfirstapp.repo;
  87.  
  88. import org.springframework.data.jpa.repository.JpaRepository;
  89.  
  90. import springbootfirstapp.domain.Customer;
  91.  
  92. public interface CustomerRepo extends JpaRepository<Customer, Integer> {
  93.  
  94. }
  95.  
  96. spring.datasource.url=jdbc:mysql://localhost:3306/springbootfirstapp
  97. spring.datasource.username=root
  98. spring.datasource.password=
  99. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  100. spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
  101. spring.jpa.hibernate.ddl-auto=update
Add Comment
Please, Sign In to add comment