我有方法,该方法按团队类中的国家/地区对数据库中的数据进行排序。 Hibernate在List <>中返回我的数据。 TeamsDao我的休眠方法。
我的错误日志:
**
There was an unexpected error (type=Internal Server Error, status=500).
class com.champions.league.model.Teams cannot be cast to class com.champions.league.model.Teams (com.champions.league.model.Teams is in unnamed module of loader 'app'; com.champions.league.model.Teams is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @169e859a)
java.lang.ClassCastException: class com.champions.league.model.Teams cannot be cast to class com.champions.league.model.Teams (com.champions.league.model.Teams is in unnamed module of loader 'app'; com.champions.league.model.Teams is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @169e859a)
我的控制器:
@Controller
@RequestMapping("/teams")
public class ChampLeagueController {
@GetMapping
public String showDesignForm(Model model){
List<Teams> teamsList = TeamsDao.findAll();
Teams.Countries[] countries = Teams.Countries.values();//Значение стран для фронта
for(Teams.Countries country: countries){
model.addAttribute(country.toString().toLowerCase(), filterByCountry(teamsList, country));
}
model.addAttribute("ChampionsLeague", new ChampionsLeague());
return "ChampionsLeague";
}
public ArrayList<Teams> filterByCountry(List<Teams> teamsList, Teams.Countries country){
ArrayList<Teams> sortedList = new ArrayList<>();
for (Teams teams : teamsList) {
if (teams.getCountries() == country)
sortedList.add(teams);
}
return sortedList;
}
}