百里香帮助。 th:每个都不可序列化

时间:2016-11-15 16:38:06

标签: java html

我是ThymeLeaf的新手,我很难理解我得到的错误。图为我得到的错误。这个项目给了我更多的文件。虽然这些是我认为对我遇到的问题很重要的文件,但由于我对这个问题知之甚少,我不太确定。
ThymeLeaf Error

Java,CSS和HTML

package com.newconstructs.service.api;

import com.newconstructs.domain.Animal;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Map;


@Validated
public interface AnimalService {
  public List<Animal> findAll();
}


package com.newconstructs.domain;

public class Animal {
  public enum AnimalType {DOG, CAT, SNAKE, RABBIT}


  private AnimalType animalType;
  private String     name;
  private int        offense;
  private int        defense;
  private int        health;
  private int        items;

  public Animal(AnimalType animalType, String name, int offense, int defense, int health, int items) {

    this.animalType = animalType;
    this.name = name;
    this.offense = offense;
    this.defense = defense;
    this.health = health;
    this.items = items;
  }

  public AnimalType getAnimalType() {

    return animalType;
  }

  public void setAnimalType(AnimalType animalType) {

    this.animalType = animalType;
  }

  public String getName() {

    return name;
  }

  public void setName(String name) {

    this.name = name;
  }

  public int getOffense() {

    return offense;
  }

  public void setOffense(int offense) {

    this.offense = offense;
  }

  public int getDefense() {

    return defense;
  }

  public void setDefense(int defense) {

    this.defense = defense;
  }

  public int getHealth() {

    return health;
  }

  public void setHealth(int health) {

    this.health = health;
  }

  public int getItems() {

    return items;
  }

  public void setItems(int items) {

    this.items = items;
  }
}

package com.newconstructs.service;

import com.newconstructs.domain.Animal;
import com.newconstructs.domain.Animal.AnimalType;
import com.newconstructs.service.api.AnimalService;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class AnimalServiceImpl implements AnimalService {
  private static final List<Animal> ANIMALS;

  static {
    ANIMALS = new ArrayList<>();

    ANIMALS.add(new Animal(AnimalType.DOG, "Spot", 10, 7, 17, 0));
    ANIMALS.add(new Animal(AnimalType.DOG, "Rover", 15, 5, 2, 6));
    ANIMALS.add(new Animal(AnimalType.DOG, "Fido", 8, 6, 12, 15));
    ANIMALS.add(new Animal(AnimalType.CAT, "Mittens", 18, 3, 3, 0));
    ANIMALS.add(new Animal(AnimalType.CAT, "Snowball", 5, 0, 14, 1));
    ANIMALS.add(new Animal(AnimalType.CAT, "Waffles", 8, 11, 2, 18));
    ANIMALS.add(new Animal(AnimalType.SNAKE, "Slider", 6, 16, 14, 3));
    ANIMALS.add(new Animal(AnimalType.SNAKE, "Milton", 16, 6, 11, 17));
    ANIMALS.add(new Animal(AnimalType.SNAKE, "Spike", 6, 18, 2, 5));
    ANIMALS.add(new Animal(AnimalType.SNAKE, "Alice", 9, 11, 4, 6));
    ANIMALS.add(new Animal(AnimalType.RABBIT, "Flopsy", 14, 0, 12, 2));
    ANIMALS.add(new Animal(AnimalType.RABBIT, "Peter", 18, 18, 14, 3));
    ANIMALS.add(new Animal(AnimalType.RABBIT, "Oreo", 7, 4, 9, 1));
  }

  @Override
  public List<Animal> findAll() {

    return ANIMALS;
  }
}
a {
  text-decoration: none;
  color: black;
}


#content, #header, #footer {
  width: 600px;
}

.menu {
  display: flex;
}

.menu > a {
  border-bottom: 1px solid grey;
  border-right: 1px solid grey;
  text-align: center;
  flex-grow: 1;
  padding: 10px;
}

.menu > a.selected {
  background-color: lightgray;
}

.menu > a:last-child {
  border-right: 0;
}

.menu > a:focus, .menu > a:hover {
  background-color: #e5e5e5;
}

h2.header {
  padding-bottom: 0;
  margin-bottom: 15px;
  border-bottom: 1px solid grey;
}


.animal-list {
  width: 400px;
}


.animal {
  border-bottom: 1px solid grey;
  padding: 4px 5px;
}


.name {
  font-size: 1rem;
}

.characteristic {
  text-align: right;
}

.type {
  font-size: 0.8rem;
  float: right;
}

.rating-table, .rating-table th, .rating-table td, .stats-table, .stats-table th, .stats-table td {
  border: 1px solid grey;
  border-collapse: collapse;
  width: 4.0rem;
  padding: 4px;
}
<div id="content">
  <h2 class="header">Animal Rating</h2>
  <div class="animal-list">
    <div class="animal" th:each="animal : ${animals}">    
      <span class="name" th:text="${animal.name}">Name</span>
      <span class="type" th:text="${animal.animalType}">Animal Type</span>
    </div>
  </div>
</div>

0 个答案:

没有答案