I have exactly such a controller and it gives orders to the repository field.
@RestController
@RequestMapping (path="/quex")
public class CommentController {
@Autowired
CommentRepository repository;
@GetMapping(path="/list")
public List<String> getAllUser () {
return repository.getUserAll();
}
}
Then I defined the repository part that makes transactions on my MySQL server like this.
@Repository
public class CommentRepository {
@Autowired
JdbcTemplate jdbcTemplate;
public List<String> getUserAll () {
List<String> users = new ArrayList<>();
users.addAll(jdbcTemplate.queryForList("select * from users", String.class));
return users;
}
}
I want to get it exactly in the form of the list at the bottom.
{
"name": "Thunder",
"lastname": "Paxis",
}