inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[개념은 호옹~, 실습 빡] 스프링 부트, 입문!

19강 JSON create 메서드 질문이여!!

해결된 질문

544

반짝반짝한 사막여우

작성한 질문수 0

1

package com.example.firstproject.api;

import com.example.firstproject.dto.ArticleForm;
import com.example.firstproject.entity.Article;
import com.example.firstproject.repository.ArticleRepository;
// import lombok.AllArgsConstructor;
// import lombok.NoArgsConstructor;
// import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ArticleApiController {

private ArticleRepository articleRepository;
private ArticleForm dto;

@GetMapping("/api/articles")
public List<Article> index() {
return articleRepository.findAll();
}

@GetMapping("/api/articles/{id}")
public Article index(@PathVariable Long id) {
return articleRepository.findById(id).orElse(null);
}

@PostMapping("/api/articles")
public Article create(@RequestBody ArticleForm dto) {
Article article = dto.toEntity();
return articleRepository.save(article);
}
}

 

PostMapping하고 있는데, Talend API Tester에서 아래와 같이 실행시키면 안돼여

에러메시지는 아래와 같습니다

Cannot invoke "com.example.firstproject.repository.ArticleRepository.save(Object)" because "this.articleRepository" is null

라고 떠여... 그래서 ArticleRepository를 확인해보면

ArticleRepository는

package com.example.firstproject.repository;

import com.example.firstproject.entity.Article;
import org.springframework.data.repository.CrudRepository;
import java.util.ArrayList;

public interface ArticleRepository extends CrudRepository<Article, Long> {
@Override
ArrayList<Article> findAll();
}

으로 썜이랑 똑같이 작성했어요

 

쌤.... 제가 뭘 잘못 했나여............뭘 고치면 되나여......... 살려주십셔.,,,,,,,,,,,,,.

spring-boot restapi json createmethod 안돼여

답변 1

1

홍팍

@Autowired를 리파지터리에 적용해야쥬?

0

반짝반짝한 사막여우

ㅎㅎㅎㅎ 감사함다!

23강 댓글 생성 메소드 오류

0

94

2

15.14 강 에러 문제 질문

0

63

1

21강 자율 과제중 update

0

137

2

28강 DB mysql연동 관련 질문

0

300

1

27강 관련 질문

0

210

1

22강 관련질문

0

315

2

21강 create테스트 질문

0

362

1

9강 질문 있습니다

0

293

1

로그창에 내용이 출력이 안됩니다.

0

371

1

index()함수 질문있습니다.

0

371

3

수정완료를 눌렀을때 첫번째 데이터는 전송이 안되고 다시 수정완료 버튼을 눌러야 데이터가 전송 됩니다.

0

486

1

강의와 책 질문

0

442

1

20강 질문있습니다.

0

402

1

20강에서 Article create 부분

0

294

1

16강 질문있습니다.

0

268

1

mustache의 article의 정의가 뭔가요?

0

345

2

17강 Unique index or primary key violation

1

1840

2

8강 에러 질문있습니다.

0

274

1

15강 DB연결

0

344

1

추상클래스를 사용 할 수있을까요?

0

247

1

22강 과제 질문

0

378

1

22강 질문입니다.

0

371

1

19강 create POST 500 에러

0

459

1

15강 data.sql코드가 작동하지 않습니다.

1

665

2