Afficher les réponses JSON dans une page jsp
Je suis le tutoriel : Apprendre à développer les services REST avec Spring Boot et Spring RestTemplate https://bnguimgo.developpez.com/tuto...-resttemplate/ et j'ai un souci avec la liste des utilisateurs. En effet, celle-ci s'affiche sous format JSON et via la partie serveur, c'est-à-dire http://localhost:8080/springboot-restserver/.
Voici le code de création de la liste:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
package com.bnguimgo.springbootrestserver.controller;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.bnguimgo.springbootrestserver.model.Role;
import com.bnguimgo.springbootrestserver.model.User;
import com.bnguimgo.springbootrestserver.service.RoleService;
import com.bnguimgo.springbootrestserver.service.UserService;
@Controller
@CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
@RequestMapping("/user/*")
public class UserController {
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@GetMapping(value = "/users")
public ResponseEntity<Collection<User>> getAllUsers() {
Collection<User> users = userService.getAllUsers();
logger.info("liste des utilisateurs : " + users.toString());
return new ResponseEntity<Collection<User>>(users, HttpStatus.FOUND);
}
} |
Voici comment j'arrive à accéder à la liste des utilisateurs à partir d'une page jsp:
Code:
<a href="http://localhost:8080/springboot-restserver/user/users">liste</a>
Le lien me redirige donc vers la page http://localhost:8080/springboot-restserver/user/users et les données sont afficher sous format JSON.
Je voudrais donc afficher cette liste dans une page jsp et sous forme de tableau html.
Merci