小编gme*_*exo的帖子

Angular 6从rest api下载文件

我有我的REST API,我把我的pdf文件,现在我希望我的角度应用程序通过我的网络浏览器点击下载,但我得到了HttpErrorResponse

"位于0的JSON中出现意外的标记%"

"SyntaxError:JSON.parse中位置0↵的JSON中出现意外的标记%(

这是我的终点

    @GetMapping("/help/pdf2")
public ResponseEntity<InputStreamResource> getPdf2(){

    Resource resource = new ClassPathResource("/pdf-sample.pdf");
    long r = 0;
    InputStream is=null;

    try {
        is = resource.getInputStream();
        r = resource.contentLength();
    } catch (IOException e) {
        e.printStackTrace();
    }

        return ResponseEntity.ok().contentLength(r)
                .contentType(MediaType.parseMediaType("application/pdf"))
                .body(new InputStreamResource(is));

}
Run Code Online (Sandbox Code Playgroud)

这是我的服务

  getPdf() {

this.authKey = localStorage.getItem('jwt_token');

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/pdf',
    'Authorization' : this.authKey,
    responseType : 'blob',
    Accept : 'application/pdf',
    observe : 'response'
  })
};
return this.http
  .get("http://localhost:9989/api/download/help/pdf2", httpOptions);
Run Code Online (Sandbox Code Playgroud)

}

和调用

this.downloadService.getPdf()
  .subscribe((resultBlob: Blob) => …
Run Code Online (Sandbox Code Playgroud)

rest typescript angular6

29
推荐指数
3
解决办法
4万
查看次数

同一实体中多对多关系的无限递归

当我有用户并且他们有其他用户作为朋友时,我想制作类似于 facebook 的应用程序。所以我做了一个User与自己有 ManyToMany 关系的实体,它们也可以互相邀请到朋友列表。不幸的是,当我想获得邀请好友的用户时,我收到此错误:

Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.util.ArrayList[0]->com.pk.thesis.devbook.models.dto.UserDTO["invitedFriends"]->java.util.ArrayList[0]->com.pk.thesis.devbook.models.dto.UserDTO["invitedFriends"]->java.util.ArrayList[0]-
... (it goes forever)
>com.pk.thesis.devbook.models.dto.UserDTO["invitedFriends"]->java.util.ArrayList[0]with root cause
Run Code Online (Sandbox Code Playgroud)

我缩短的用户实体类:

    @Data
    @Entity
    @Table( name = "users", 
            uniqueConstraints = { 
                @UniqueConstraint(columnNames = "username"),
                @UniqueConstraint(columnNames = "email") 
            })
    @JsonIdentityInfo(generator= ObjectIdGenerators.UUIDGenerator.class, property="@id")
    public class User {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id;

        @NotBlank
        @Size(max = 40)
        private String username;

//other things...

        @ManyToMany(fetch …
Run Code Online (Sandbox Code Playgroud)

recursion spring hibernate jpa

3
推荐指数
1
解决办法
1337
查看次数

标签 统计

angular6 ×1

hibernate ×1

jpa ×1

recursion ×1

rest ×1

spring ×1

typescript ×1