해결된 질문
작성
·
464
·
수정됨
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();
}
으로 썜이랑 똑같이 작성했어요
쌤.... 제가 뭘 잘못 했나여............뭘 고치면 되나여......... 살려주십셔.,,,,,,,,,,,,,.
ㅎㅎㅎㅎ 감사함다!