Spring Boot 和 Angular crud 方法都可以,但是仍然不清楚如何在 spring boot 和 angular 之間系結其他方法。
Rest API,Spring Boot-Angular。發送電子郵件。
休息控制器
@PostMapping("/sendEmail")
public ResponseEntity<String> sendEmail(@PathVariable long id) throws CustomerNotFoundException{
Customer customer = customerService.findCustomer(id);
emailService.sendSimpleEmail(customer.getEmail(),
"Hi dear customer! Your order is "
"ready to pick up","Your order is waiting for you"
);
return new ResponseEntity<>("mail sent successfully", HttpStatus.OK);
}
角。帶有 http 的服務類。
sendEmail(id:any):void {
const url = 'http://localhost:8080/customers/sendEmail';
this.http.post(url,{responseType: 'text'}).subscribe(
res=>{location.reload();},
err=> {
alert('An error has occurred while sending email')
}
)
}
先感謝您。
uj5u.com熱心網友回復:
假設 CORS 已配置,您的端點也期望id.
添加{id}到您的端點。
@PostMapping("/sendEmail/{id}")
public ResponseEntity<String> sendEmail(@PathVariable long id) throws CustomerNotFoundException{
Customer customer = customerService.findCustomer(id);
emailService.sendSimpleEmail(customer.getEmail(),
"Hi dear customer! Your order is "
"ready to pick up","Your order is waiting for you"
);
return new ResponseEntity<>("mail sent successfully", HttpStatus.OK);
}
/將引數添加id到 URL 的末尾。
id = 123;
sendEmail(id:any):void {
const url = 'http://localhost:8080/customers/sendEmail/' id;
this.http.post(url,{responseType: 'text'}).subscribe(
res=>{location.reload();},
err=> {
alert('An error has occurred while sending email')
}
)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/445761.html
下一篇:為什么我的腳本正在讀取在我的HTML中鏈接的檔案,這些檔案在GoLang中使用ioutil.ReadFile()讀取時未指定?
