Ok, zrobiłem to od nowa i wygląd to tak:
Customer.java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Customer {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String address;
private String countryCode;
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
MainController.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(path="/customer")
public class MainController {
@Autowired
private CustomerRepository customerRepository;
@GetMapping("/all")
public List<Customer> getAll() {
return customerRepository.findAll();
}
@PostMapping("/create")
public List<Customer> create(@RequestBody Customer customer) {
customerRepository.save(customer);
return customerRepository.findAll();
}
@DeleteMapping("/delete/{id}")
public List<Customer> remove(@PathVariable long id) {
customerRepository.delete(id);
return customerRepository.findAll();
}
@PutMapping("/update/{id}")
public List<Customer> updateBook(@RequestBody Customer customer, @PathVariable Long id) {
Customer currentuser = customerRepository.findOne(id);
currentuser.setName(customer.getName());
currentuser.setAddress(customer.getAddress());
currentuser.setCountryCode(customer.getCountryCode());
return customerRepository.findAll();
}
}
CustomerRepository.java
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Long> {
}
aplication.properties
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/db_example?autoReconnect=true&useSSL=false
spring.datasource.username=hbcustomer
spring.datasource.password=hbcustomer
Prośba do Was o ocenę na podstawie polecenia z pierwszego postu, dzięki za odpowiedzi :)