Я получил эту ошибку в файле Userservice.java 'предполагаемый тип' S 'для параметра типа' S 'не в его пределах;'Я не знаю, о чем идет речь и где я должен измениться .. пожалуйста, проверьте мой файл и дайте мне несколько советов
введите описание изображения здесь
package com.therealdanvega.service;
import com.therealdanvega.domain.User;
import com.therealdanvega.repository.UserRepository;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserService {
private UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public Iterable<User> list() {
return userRepository.findAll();
}
public User save(User user) {
return userRepository.save(user);
}
public void save(List<User> users) {
userRepository.save(users);
}
}
User
package com.therealdanvega.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import javax.persistence.*;
@Data
@AllArgsConstructor
@Entity
public class User {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
private Long id;
private String name;
private String username;
private String email;
private String phone;
private String website;
@Embedded
private Address address;
@Embedded
private Company company;
public User() {}
}
UserController
package com.therealdanvega.controller;
import com.therealdanvega.domain.User;
import com.therealdanvega.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/users")
public class UserController {
private UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping("/list")
public Iterable < User > list() {
return userService.list();
}
}
JsondbApplication
package com.therealdanvega;
import com.fasterxml.jackson.core.type.TypeReference;
import com.therealdanvega.domain.User;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.therealdanvega.service.UserService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@SpringBootApplication
public class JsondbApplication {
public static void main(String[] args) {
SpringApplication.run(JsondbApplication.class, args);
}
@Bean
CommandLineRunner runner(UserService userService){
return args -> {
// read JSON and load json
ObjectMapper mapper = new ObjectMapper();
TypeReference<List<User>> typeReference = new TypeReference<List<User>>(){};
InputStream inputStream = TypeReference.class.getResourceAsStream("/json/users.json");
try {
List<User> users = mapper.readValue(inputStream,typeReference);
userService.save(users);
System.out.println("Users Saved!");
} catch (IOException e){
System.out.println("Unable to save users: " + e.getMessage());
}
};
}
}
UserRepository
package com.therealdanvega.repository;
import com.therealdanvega.domain.User;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User,Long> {
}
В классе UserService в методе сохранения (список пользователей)userRepository.save (users) throw error Ошибка предполагаемого типа 'S' для параметра типа 'S' не входит в его пределы;должен расширить 'com.therealdanvega.domain.User'