1
I have the model:
@Data
@RedisHash("customer")
public class Customer {
@Id
private String id;
@NotNull
private String firstName;
...
I have the following interface:
@EnableRedisRepositories
public interface CustomerRepository extends JpaRepository<Customer, String> {
Optional<Customer> findByFirstName(String firstName);
}
The Service:
@Service
@Transactional
public class CustomerService {
private final CustomerRepository repository;
public CustomerService(CustomerRepository repository) {
this.repository = repository;
}
...
public Optional<Customer> retrieveCustomersByName(String name) {
return repository.findByFirstName(name);
}
}
And the following restcontroller:
@RestController
@RequestMapping("/customers")
public class CustomerController {
@Autowired
private CustomerService customerService;
....
@GetMapping("/{firstName}")
public ResponseEntity<?> getCustomers(@PathVariable String firstName) {
Optional<?> customer = customerService.retrieveCustomersByName(firstName);
if (!customer.isPresent()) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(customer);
}
}
All methods of crud are ok!
However when I do the query by Postman it does not return any redis result. What should I do?
url used in Postman:
http://localhost:9000/api/customers/paulo
application.yml file:
server:
port: 9000
servlet:
contextPath: /api
Sorry to be unaware, but I have not seen "api" mapped anywhere in your code, it is necessary that it is in the url?
– Scarabelo
@Scarabelo That nothing, the "api" is mapped in the application.properties file, but in my case, this mapped in the application.yml file , that gives in the same. I’ll put it in the code above -
– Pena Pintada