首页 > 解决方案 > 使用 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();
  }

  }

标签: javaangulareclipserest

解决方案


推荐阅读