我在通过http.post向后端发送JSON字符串时遇到了一些麻烦。我正在研究一个已经拥有其结构和一切的项目。
我创建了一个PaymentResource.java文件,充当此功能的REST控制器。我还创建了一个PaymentService。从TypeScript文件调用时,我称之为
this.http.post(SERVER_API_URL +'path / anotherpath',request);
这是我的PaymentResource文件
@RestController
@RequestMapping("/path")
public class PaymentResource {
private final Logger log = LoggerFactory.getLogger(PaymentResource.class);
public PaymentResource(){
}
@PostMapping("/anotherpath")
@ResponseStatus(value = HttpStatus.OK)
public void tokenize(@RequestBody String body) {
log.logger("here");
}
}
字符串tokenize方法永远不会被执行,因为我看不到日志。
任何帮助表示赞赏! 谢谢!
答案 0 :(得分:0)
我明白了。我错过了component.ts上的订阅:
this.paymentService.sendInfo().subscribe((response) => {
console.log(response.ok);
});
和service.ts文件中的Observable。