Bonjour, je développe une application back springboot.
Voici mon controlleur
Voici mon pom.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package com.example.demoImmobilierBack.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.example.demoImmobilierBack.dto.DossierPinelDTO; import com.example.demoImmobilierBack.dto.ProduitImmobilierDTO; import com.example.demoImmobilierBack.service.ProduitImmobilierServiceImpl; @CrossOrigin(origins = "http://localhost:4200", maxAge = 3600) @RestController @RequestMapping({"/api"}) public class ProduitImmobilierController { @Autowired private ProduitImmobilierServiceImpl userService; @RequestMapping(value = "/produitimmobilier/all", method = RequestMethod.GET, produces = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE}, consumes = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody List<ProduitImmobilierDTO> findAll(){ return userService.findAll(); } @RequestMapping(value = "/produitimmobilier/{id}", method = RequestMethod.GET, produces = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE}, consumes = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody DossierPinelDTO findOne(@PathVariable("id") int id){ return userService.findById(id); }
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demoImmobilierBack</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demoImmobilierBack</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency> <dependency> <groupId>org.hibernate.hql</groupId> <artifactId>hibernate-hql-parser</artifactId> <version>1.5.0.Final</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-releases</id> <name>Spring Releases</name> <url>https://repo.spring.io/libs-release</url> </repository> <repository> <id>org.jboss.repository.releases</id> <name>JBoss Maven Release Repository</name> <url>https://repository.jboss.org/nexus/content/repositories/releases</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-releases</id> <name>Spring Releases</name> <url>https://repo.spring.io/libs-release</url> </pluginRepository> </pluginRepositories> </project>
Je vais à l'adresse url : http://localhost:8080/api/produitimmobilier/all. J'attends en retour un json. Dans la console de firefox, j'ai le message d'erreur suivant :
et mon onglet réseau de firefox m'indique une erreur 404 dans l'entête de ma requête. Je sais que ma réponse inclus des caractères spéciaux comme des vraie apostrophe, ce qui peut être la source de l'erreur. Hier j'arrivais à obtenir la réponse json par moment (elle s'affichait dans la page), mais plus aujourd'hui. Pouvez vous m'aider ?L’encodage de caractères d’un document en texte brut n’a pas été déclaré. Le document sera affiché avec des caractères incorrects pour certaines configurations de navigateur si le document contient des caractères en dehors de la plage US-ASCII. L’encodage de caractères du fichier doit être déclaré dans le protocole de transfert ou le fichier doit utiliser une marque d’ordre des octets (BOM) comme signature d’encodage.
Partager