J'ai un contrôleur pour renvoyer un Payload JSONSpring MVC préparation JSON mais le chargement d'une page à la place
@RequestMapping(value = "/MerchantMonitoringAPI", method = RequestMethod.GET,produces = "application/json")
public String MerchantMonitoring() {
ApplicationContext context =
new ClassPathXmlApplicationContext("Spring-Module.xml");
TopMerchantsDAO topMerchantsDAO = (TopMerchantsDAO) context.getBean("topMerchantsDAO");
TopMerchants topMerchants = topMerchantsDAO.retrieveMerchantList();
for(String temp:topMerchants.getMerchantList())
{
System.out.println(temp);
}
Gson gson = new Gson();
Type type = new TypeToken<TopMerchants>() {}.getType();
String jsonPayload = gson.toJson(topMerchants, type);
System.out.println(jsonPayload);
return jsonPayload;
}
Il essaie de me rediriger vers une vue avec le nom de la page comme JSON (localhost: 8080/{"merchantList": ["Apple", "Google"]}. jsp)
Comment arrêter ceci et renvoyer la charge utile JSON ??
pouvez-vous ajouter ce @RestController sur le RequestMapping? –
@georgesvan qui a fonctionné! –
Nice. N'hésitez pas à valider ma réponse ci-dessous –