2 回答
TA贡献1831条经验 获得超4个赞
您可以在春季MVC中轻松完成,我将向您解释一种简单的方法。
首先,从表单中获取值并将其更改为 JSON 格式。
然后将其以 JSON 格式发送到另一个应用程序。
在其他 Web 应用程序中,获取 JSON 文件并显示它。喜欢这个
这里有一些例子,你可以试试自己的
在控制器中获取 JSON 值
//You can use @RestController or @ResponseBody to send a response in JSON format
@PostMapping(value = "/test", consumes = MediaType.APPLICATION_JSON_VALUE)
public MOResponse receiveNotification(@RequestBody MO mo) {
studentService.getStudent(mo);
MOResponse moResponse = new MOResponse("S1000", "Success");
return moResponse;
}
在此处将 POST 请求发送到另一个 API,此请求以字符串格式发送,但您可以更改为 JSON 格式
public void sendMT() {
RestTemplate restTemplate = new RestTemplate();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
final String uri = "http://localhost:7000/sms/send";
try {
String json = ow.writeValueAsString(mt);
RequestEntity<String> requestEntity = RequestEntity.post(new URL(uri).toURI()).contentType(MediaType.APPLICATION_JSON).body(json);
ResponseEntity<String> output = restTemplate.exchange(requestEntity, String.class);
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
在上面的例子中,我用过
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
记住这个例子只是为了得到一个想法。你可以创造自己的,祝你好运
TA贡献2012条经验 获得超12个赞
mi的第一个建议是参加课程 https://dzone.com/articles/top-5-courses-to-learn-spring-boot-in-2019
其实是很容易学弹簧与弹簧靴,请回顾弹簧靴,这是解决你的问题。
添加回答
举报
