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
其實是很容易學彈簧與彈簧靴,請回顧彈簧靴,這是解決你的問題。
添加回答
舉報