스프링 MVC를 사용하여 하위 목록과 함께 목록의 내용을 인쇄

Jchrshnkr :

어떻게 하위 목록과 함께 목록의 내용을 인쇄합니다.? 누군가의 도움이 나를 어떻게 완벽한 서비스 클래스 로직을 수행 할 수 있습니다? 문제는 다음이었다 아래로 넷 플레이에 대한 프로그램을 만듭니다. 홈페이지 목록 - 카테고리 분류의 하위 목록 - 코스

Categories Sample Data: (Add first 3 categories from the netplay app)
 "id": 1001,
 "name": "Computing",
 "description": "network of remote servers"here

Course Sample Data:(Add first 3 courses on every category added from the netplay app)
id : 2001,
Category id: 1001,
name : "AWS"
duration : 180
miles :100

이 방법 여기 로직을 ​​구현하는 하위리스트와 함께 목록의 내용을 반환하는 서비스 클래스

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

import org.springframework.stereotype.Service;

@Service
public class ContentService {

 private List<Category> categories=new ArrayList<>(Arrays.asList(new Category(1001, "Computing", "network of remote servers"));

//put your code here.
public List<Category> getAllContent() {
    return categories;

}
}
Kosonome :

당신이 때문에 @RestController이미 목록을 반환하는 것 Category이 범주가 이미 목록 내부가 Course의, 당신은 당신의 서비스 내부 과정으로 범주를 채울 필요가있다.

@Service
public class ContentService {
  private List<Category> categories = new ArrayList<>();

  public List<Category> getAllContent() {
    List<Course> courses = new ArrayList<>();
    courses.add(new Course(1, "Coursename", 200, 200, 1001));

    List<Category> categories = new ArrayList<>();
    categories.add(new Category(1001, "Computing", "network of remote servers", courses));
    return categories;
  }
}

추천

출처http://43.154.161.224:23101/article/api/json?id=336462&siteId=1