我是Spring的新手。我有一个名为Order的模型,它有像
这样的字段ID,状态,时间戳,CUSTOMER_ID 其中status是枚举类型。 模型看起来像
@Entity
@Table(name="order_")
public class Order
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long id;
@ManyToOne
@NotNull
public Customer customer;
@Temporal(TemporalType.TIMESTAMP)
@NotNull
@LastModifiedDate
@JsonFormat(shape=JsonFormat.Shape.STRING)
public Date timestamp;
@OneToMany(fetch=FetchType.EAGER)
@OrderColumn(nullable = false)
public List<OrderItem> items = new ArrayList<OrderItem>();
@Enumerated(EnumType.STRING)
@NotNull
public Status status = Status.UNCLAIMED;
public static enum Status
{
UNCLAIMED,
PICKUP, // pickup on the way
DELIVERY, // delivery on the way
DELIVERED,
}
public static interface Repository extends PagingAndSortingRepository<Order, Long>
{
public List<Order> findTop2ByCustomerIdAndStatus(@Param("customer_id") Long customer_id, @Param("status") String status);
}
}
当我运行api终点时 http://localhost:8080/api/v1/orders/search/findTop2ByCustomerIdAndStatus?customer_id=1&status=&#39; UNCLAIMED&#39;
我收到的回复是
{
"timestamp": 1440744058472,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.InvalidDataAccessApiUsageException",
"message": "Parameter value [('UNCLAIMED')] did not match expected type [app.models.Order$Status (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [('UNCLAIMED')] did not match expected type [app.models.Order$Status (n/a)]",
"path": "/api/v1/orders/search/findTop2ByCustomerIdAndStatus"
}
请建议