java - 使用 POST 方法的 REST 服务中的字符串参数
问题描述
我有 2 个项目:其中一个是 Angular 前端应用程序,另一个是后端,是一个动态 Web 项目。我的 IDE 是 Eclipse。以下 POST 方法不起作用,每次运行该方法时,我都会进入 Eclipse 控制台 null。我只需要在我的控制台中显示一个字符串参数。
Java中的POST方法:
@POST
@Path("add")
@Produces(MediaType.TEXT_PLAIN)
public void addSelection(@FormParam("id") String id) {
System.out.print(id);
}
Angular 中的服务:
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
//import { HttpErrorHandler, HandleError } from '../http-error-handler.service';
@Injectable()
export class App {
constructor(private http: HttpClient){
}
addWord(word: string) {
this.http.post('http://localhost:8080/***/add', word).subscribe();
}
}
解决方案
推荐阅读
- html - 我第一次打开网站时看到的故障有什么解决方案吗?
- css - 使用 Flexbox 时隐藏伪元素后
- ios - UIView 没有正确更新
- sql - 将行转换为列
- wordpress - 使用 WPS 隐藏登录插件后,我被锁定在 WordPress 之外
- swift - 在 Xcode 中找不到文件
- python - 如何使用 python 通过子值从 YAML 文件中获取父 ID?
- c# - 以编程方式将父 ViewModel 的命令添加到按钮
- python - 如何使用 tf.data.Dataset.from_tensor_slices 和 map 加载 np.array
- django - 将 websockets 集成到 Django Rest Framework 应用程序的简单方法?