'How to show and edit specific fiels in Spring Boot?
I have this project where I created two tables with secondary table(linked by id) and I need to show and edit them separately.
this is my model
@Entity
@Table(name= "products")
@SecondaryTable(name = "tb_status", pkJoinColumns = @PrimaryKeyJoinColumn(name = "products_id"))
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "name")
@Size(max=255)
private String name;
@Column(name = "type")
private int type;
@Column(name = "status", table = "tb_status")
private boolean status;
I am trying but I was unsuccessful to create a way to create methods to show and one to edit these tables separately.
My repository
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
public List<Product> findAllByNameContainingIgnoreCase(String name);
}
My Controller
@GetMapping
public ResponseEntity<List<Product>> GetAll(){
return ResponseEntity.ok(repository.findAll());
}
@PutMapping
public ResponseEntity<Product> putPostagem(@RequestBody Product product){
return repository.findById(product.getId())
.map(resposta -> ResponseEntity.ok(repository.save(product)))
.orElse(ResponseEntity.notFound().build());
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
