Ошибка 415 Неподдерживаемый тип носителя. Запрос не достигает моего сервера - PullRequest
0 голосов
/ 02 июня 2019

Я новичок в Angular и SpringBoot и пытаюсь создать приложение. Я хочу отправить данные из Angular в SpringBoot. Однако я получаю ошибку. Я думаю, что проблема с SpringBoot, но я не уверен. Любая помощь будет очень высоко ценится.

Вот мой код:

Угловая

issue.component.ts

import { Component, OnInit, DoCheck } from '@angular/core';
import { IssuesService } from '../issues.service';
import { HttpClientModule } from '@angular/common/http';
import { Http } from '@angular/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Observable} from 'rxjs';


@Component({
  selector: 'app-issue',
  templateUrl: './issue.component.html',
  styleUrls: ['./issue.component.css']
})
export class IssueComponent implements OnInit,  DoCheck {

  constructor(private issue: IssuesService, private httpClient: HttpClient) { }

issueInfo: any[] = [];
issueInformation: any;

ngDoCheck(): void {
        console.log('issue:', this.issueInformation);
    }

  ngOnInit() {
    this.getIssues();
  }
    getIssues() {

        console.log('issue::', this.issueInformation);

        this.issue.allIssues().
    subscribe(
      data2 => {
          this.issueInfo = data2.Issues;

      },
      err => console.log(err),
      () => console.log('complete')
    );

  }
  apiService(issue1: IssueComponent): Observable<any> {
     console.log('post issue asdh');
     return this.httpClient.post('http://localhost:8080/postIssue', issue1);
  }
   sendIssue(): void {
           this.apiService(this.issueInformation).subscribe(
                 res => {
                         location.reload();
                               },
                                     err => {
                                             alert('An error has occurred while sending issue');
                                                   }
                                                       );
                                                         }


}

issue.component.html

<form #userForm="ngForm">
<div class="form-group">
   <label>Select Issue</label>
        <select class="form-control"  [(ngModel)]="issueInformation" id="issue" name="issue" >
        <option *ngFor="let issue of issueInfo"  [value]="issue.IssueName">{{issue.IssueName}}</option>
      </select>  
</div>
<button (click)="sendIssue()" value="Submit Issue">Submit</button>
</form>

issues.service.ts

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Response, Headers, RequestOptions} from '@angular/http';
import { Observable} from 'rxjs';
import { IssueComponent } from './issue/issue.component';


@Injectable({
  providedIn: 'root'
})


export class IssuesService {


  url = 'http://localhost:8080/issueTypes';
    httpClient: any;
    issueInformation: any;
  constructor(private http: HttpClient) { }

  allIssues(): Observable<any> {
    return this.http.get(this.url);
  }

}

SPRING-BOOT

DropDownController.java

@RestController
@CrossOrigin(origins = "http://localhost:4200")
public class DropDownController {
    ModelAndView mav = null;
    @Value("#{'${issues}'.split(',')}")
    private List<String> issues;
    @Value("#{'${granularities}'.split(',')}")
    private List<String> granularities;

    @RequestMapping(value = "/issueTypes", produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, List<Map.Entry<String, String>>> getIssue() {
        Map<String, List<Map.Entry<String, String>>> m = new LinkedHashMap<>();
        m.put("Issues", issues.stream().map(
                s -> Map.entry("IssueName", s)).collect(Collectors.toList()));
        return m;
    }

    @RequestMapping(value = "/granularityTypes", produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, List<Map.Entry<String, String>>> getGranularity() {
        Map<String, List<Map.Entry<String, String>>> n = new LinkedHashMap<>();
        n.put("Granularities", granularities.stream().map(
                t -> Map.entry("GranularityName", t)).collect(Collectors.toList()));
        return n;
    }

    @RequestMapping("/process")
    public String processForm(@Valid @ModelAttribute("di") DropdownIssue di1, @Valid @ModelAttribute("dg") DropdownGranularity dg1,BindingResult result)
    {
        if(result.hasErrors())
        {
            System.out.println("Validation Failed");
            return "SpringMVC_DropdownExample";
        }
        else
        {
            System.out.println("Validated Successfully");
            return "dropdown_Success";
        }
    }
    private IssueSender issueSender;

    public DropDownController(IssueSender issueSender) {
        this.issueSender = issueSender;
    }

      @PostMapping("/postIssue")
    public void sendFeedback(@RequestBody DropdownIssue dropdownIssue,
                             BindingResult bindingResult){


        this.issueSender.sendIssue(
                dropdownIssue.getIssues());
    }

}

IssueSender.java

package com.example.demo.mail;

import org.springframework.stereotype.Component;

@Component
public class IssueSender {
    public void sendIssue(String issue) {
    }

}

И ошибка, которую я получаю:

Imgur Что я могу с этим поделать?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...