我编写了简单的web服务,它有4个方法:我在getFilmList上停了下来。当我运行项目时,我在WizToolsRestClient中收到错误:415 Unsuported ..,并在tomcat中记录:
sty 18, 2016 5:13:12 PM com.sun.jersey.spi.container.ContainerRequest getEntity
SEVERE: A message body reader for Java class Request.Request, and Java type class Request.Request, and MIME media type application/json; charset=UTF-8 was not found.
The registered message body readers compatible with the MIME media type are:
application/json; charset=UTF-8 ->
我在DAO中的方法:
public List<Film> listFilms (Date date)
{
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try{
transaction = session.beginTransaction();
Query query = session.createQuery("FROM film WHERE date = :date");
query.setDate("date" , date);
List<Film> films = query.list();
return films;
}
catch (HibernateException e)
{
e.printStackTrace();
}
return null;
}
WebService中的实现:
@POST
@Produces("application/json")
@Consumes("application/json")
@Path("/list")
public Response getFilmList (Request request)
{
Response response = new Response();
try {
response.setFilms(dao.listFilms(request.getFilm().getDate()));
}
catch (HibernateException e)
{
}
return response;
}
实体类电影:
@Entity
@XmlRootElement
@Table (name = "film")
public class Film
{
@Id
@Column (name = "id")
@GeneratedValue (strategy = GenerationType.IDENTITY)
private int id;
@Column (name = "title")
private String title;
@Column (name = "date")
private Date date;
public Film() {} //Constuctor
// geter and seter
请求:
public class Request
{
Film film = new Film();
public Request() {
}
// geter and seter
响应:
public class Response
{
private List<Film> films;
public Response() {
}
和我的json
{
"Film":
{
"date" : "2016-01-21"
}
}
我做错了什么?