BAEL-2413 - Integrating Spring Boot with HSQLDB (#5891)
* Initial Commit * Update source file location * Update CustomerControllerUnitTest.java * Update CustomerControllerUnitTest.java * Update CustomerControllerUnitTest.java * Update source files * Update CustomerController.java * Update CustomerController.java * Update CustomerControllerUnitTest.java * Update CustomerControllerUnitTest.java * Update CustomerControllerUnitTest.java * Update index.html * Update persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/springboothsqldb/application/controllers/CustomerController.java Co-Authored-By: alejandrogervasio <alejandro.gervasio@gmail.com> * Update CustomerController.java * Update CustomerControllerUnitTest.java * Update CustomerController.java * Update CustomerControllerUnitTest.java * Update CustomerControllerUnitTest.java
This commit is contained in:
committed by
KevinGilmore
parent
53abf6733d
commit
3064a22a7a
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.springboothsqldb.application;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.springboothsqldb.application.controllers;
|
||||
|
||||
import com.baeldung.springboothsqldb.application.entities.Customer;
|
||||
import com.baeldung.springboothsqldb.application.repositories.CustomerRepository;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class CustomerController {
|
||||
|
||||
private final CustomerRepository customerRepository;
|
||||
|
||||
@Autowired
|
||||
public CustomerController(CustomerRepository customerRepository) {
|
||||
this.customerRepository = customerRepository;
|
||||
}
|
||||
|
||||
@PostMapping("/customers")
|
||||
public Customer addCustomer(@RequestBody Customer customer) {
|
||||
customerRepository.save(customer);
|
||||
return customer;
|
||||
}
|
||||
|
||||
@GetMapping("/customers")
|
||||
public List<Customer> getCustomers() {
|
||||
return (List<Customer>) customerRepository.findAll();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.baeldung.springboothsqldb.application.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "customers")
|
||||
public class Customer {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
public Customer() {}
|
||||
|
||||
public Customer(String name, String email) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Customer{" + "id=" + id + ", name=" + name + ", email=" + email + '}';
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.springboothsqldb.application.repositories;
|
||||
|
||||
import com.baeldung.springboothsqldb.application.entities.Customer;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CustomerRepository extends CrudRepository<Customer, Long> {}
|
||||
Reference in New Issue
Block a user