Postingan lainnya
Postman API Call hanya "1"/Blank di body
Bagaiman Cara mengatasi problem seperti ini pada postman ?
Capture1.PNG
My package com.bittama.customer.controllers @Post
@PostMapping("/customers")
public ResponseEntity<List<Customer>> testArrayOfValues(
@RequestBody List<Customer> customer) {
try {
Customer newCustomer = new Customer();
newCustomer.setId(UUID.randomUUID().toString());
newCustomer.setName(((Customer) customer).getName());
newCustomer.setAddress(((Customer) customer).getAddress());
newCustomer.setEmail(((Customer) customer).getEmail());
newCustomer.setPhone(((Customer) customer).getPhone());
List<Customer> List1 = List.of(newCustomer);
return new ResponseEntity<>(customerRepository.saveAll(List1), HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
My package com.bittama.customer.entities
package com.bittama.customer.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Entity
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String id;
private String name;
private String address;
private String email;
private String phone;
}
My package com.bittama.customer.repositories
ackage com.bittama.customer.repositories;
import com.bittama.customer.entities.Customer;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CustomerRepository extends JpaRepository<Customer, String> {
public List<Customer> findByNameContaining(String name);
}
0
2 Jawaban:
<div>Coba cek artikel ini ya<br><a href="https://community.postman.com/t/api-call-returning-a-1-in-the-body/14741/3">https://community.postman.com/t/api-call-returning-a-1-in-the-body/14741/3</a></div>
0
Tanggapan
Maaf mas, bukannya yg di artikel menggunakan PHP ? Sedangkan saya menggunakan java, apakak sama dalam penanganannya ?
<div>Maaf mas, bukannya yg di artikel menggunakan PHP ? Sedangkan saya menggunakan java, apakak sama dalam penanganannya ?</div>
0