SHARE
TWEET

Untitled

a guest Jan 26th, 2019 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Entity
  2. @Table(name="user")
  3. public class User {
  4.  
  5. @Id
  6. @GeneratedValue(strategy= GenerationType.AUTO)
  7. private long id;
  8.  
  9. @Column(name="userName")
  10. private String userName;
  11.  
  12. @Column(name="email")
  13. private String email;
  14.  
  15. @Column(name="password")
  16. @Transient
  17. private String password;
  18.  
  19. @Column(name="logged")
  20. private boolean logged;
  21.  
  22. @OneToOne(cascade= {CascadeType.MERGE,CascadeType.PERSIST})
  23. @JoinColumn(name = "customer_id")
  24. private Customer customer;
  25.  
  26. public User() {
  27.  
  28. }
  29.  
  30. public User(String userName,String password,String email) {
  31.     this.userName=userName;
  32.     this.password=password;
  33.     this.email=email;
  34.  
  35. }
  36.    //Getters y Setters
  37.   //
  38.    
  39. @Entity
  40. @Table(name = "customer")
  41. public class Customer {
  42.  
  43. @Id
  44. @GeneratedValue(strategy = GenerationType.AUTO)
  45. private long id;
  46.  
  47. @Column(name = "name")
  48. private String name;
  49.  
  50. @Column(name = "age")
  51. private int age;
  52.  
  53. @OneToOne(mappedBy="customer")
  54. private User user;
  55.  
  56. public Customer() {
  57. }
  58.  
  59. public Customer(String name, int age) {
  60.     this.name = name;
  61.     this.age = age;
  62.  
  63. }   public Customer(String name, int age,User user) {
  64.     this.name = name;
  65.     this.age = age;
  66.     this.user = user;
  67.    }
  68.    //Getters y Setters
  69.   //
  70.    
  71. @CrossOrigin(origins = "http://localhost:8080")
  72. @RestController
  73. @RequestMapping("/api")
  74. public class UserController {
  75.  
  76. @Autowired
  77. UserRepository userRepository;
  78.  
  79. @PostMapping("/user")
  80. public User postUser(@RequestBody User user) {
  81.     User _user = userRepository.save(new
  82. User(user.getUserName(),user.getPassword(),user.getEmail()));
  83.     return _user;
  84.  
  85. }
  86.    
  87. @CrossOrigin(origins = "http://localhost:8080")
  88. @RestController
  89. @RequestMapping("/api")
  90. public class CustomerController {
  91.  
  92. @Autowired
  93. CustomerRepository customerRepository;
  94.  
  95. @PostMapping("/customer")
  96. public Customer postCustomer(@RequestBody Customer customer) {
  97.  
  98.     Customer _customer = customerRepository.save(new
  99. Customer(customer.getName(), customer.getAge()));
  100.     return _customer;
  101. }
  102.    
  103. <template>
  104.   <div>
  105.    <form>
  106.      <b-btn v-b-modal.signupmodal size="sm" class="btn my-2 my-sm-0">
  107.      Sign up</b-btn>
  108.  
  109. <b-modal id="signupmodal"
  110.    name="signupmodal"
  111.     v-model="signupmodal">
  112.  
  113.      <div>
  114.        <label>UserName: </label>
  115.         <input v-model="user.userName" type="text" class="form-control>
  116.      </div>
  117.      <div>
  118.        <label>Password: </label>
  119.         <input v-model="user.password" type="password" class="form-control">
  120.      </div>
  121.      <div>
  122.        <label>Email: </label>
  123.         <input v-model="user.email" type="email" class="form-control">
  124.      </div>
  125.      <div>
  126.       <label>Name: </label>
  127.          <input v-model="customer.name" type="text" class="form-control">
  128.      </div>
  129.      <div>
  130.        <label>Age: </label>
  131.          <input v-model="customer.age" type="number" class="form-control">
  132.       </div>
  133.       <div slot="modal-footer" class="w-100">
  134.      <button  v-on:click="saveCustomerModal" class="btn btn-success"
  135.      >Sub</button>  
  136.      </div>  
  137.         </b-modal>
  138.       </form>
  139.     </div>
  140.    </template>
  141.    <script>
  142.     import {AXIOS} from './http-common'
  143.  
  144.      export default {
  145.      name:'signupmodal',
  146.  
  147.      data(){
  148.      return {
  149.  
  150.     signupmodal:false,
  151.     customer: {
  152.     id: 0,
  153.     name: "",
  154.     age: 0,
  155.               },
  156.    user:{
  157.    id:0,
  158.    password:"",
  159.    userName:"",
  160.    email:"",
  161.    }
  162.  };
  163.    },
  164.    methods:{
  165.   showSignUPModal(){
  166.   this.signupmodal=true
  167.    },
  168.   saveCustomerModal() {
  169.     var data = {
  170.     name: this.customer.name,
  171.     age: this.customer.age,
  172.   }
  173.   var dataUser={
  174.     userName:this.user.userName,
  175.     password:this.user.password,
  176.     email:this.user.email
  177.   }
  178.  
  179.     AXIOS.post( "/customer",data)
  180.     .then(response => {
  181.       this.customer.id = response.data.id;
  182.       console.log(response.data);
  183.     })
  184.     .catch(e => {
  185.       console.log(e);
  186.     });
  187.  
  188.        AXIOS.post( "/user",dataUser)
  189.     .then(response => {
  190.       this.user.id = response.dataUser.id;
  191.       console.log(response.Userdata);
  192.     })
  193.     .catch(e => {
  194.       console.log(e);
  195.     })
  196.     },
  197.   }
  198. };
  199.    </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top