出现415 unsupprot media Type 错误和 InputStream close 错误的解决方法如下:
解决方法:由于cxf 对元素进行了封装,它有一个注解叫作@FormParam和QueryParam,@FormParam 用于更新和添加,QueryParam 用于查询。刚开始我还以为是我的@Consume 接收的类型错了,后来我发现了这个秘密,但是你的@Consumes 也必须写正确,写不对也报错,写错了没有加这个注解也报415错误,cxf 里面的封装没有spring那么牛,直接就给你弄成对象了,你直接写个对象它会报错的。
这是pojo的写法
@Path("customers")
@XmlRootElement(name="studentVO")
public class StudentVO {
private String sNo;
@FormParam("sName")
private String sName;
@FormParam("sAge")
private Integer sAge;
@FormParam("sSex")
private String sSex;
public String getsNo() {
return sNo;
}
public void setsNo(String sNo) {
this.sNo = sNo;
}
public String getsName() {
return sName;
}
public void setsName(String sName) {
this.sName = sName;
}
public Integer getsAge() {
return sAge;
}
public void setsAge(Integer sAge) {
this.sAge = sAge;
}
public String getsSex() {
return sSex;
}
public void setsSex(String sSex) {
this.sSex = sSex;
}
public String toJson() {
return JSON.toJSONString(this);
}
}
接下来这是接口的写法
@GET
@Path(value ="/selectStudentBysNo2/{sNo}")
@Produces("application/json")
@Consumes({"text/plain","application/json","application/xml"})
StudentVO selectStudentVOBysNo2(@PathParam("sNo") String sNo);
@POST
@Path(value="/updateStudent")
@Produces("application/json")
@Consumes("application/x-www-form-urlencoded; charset=UTF-8")
Response updateStudent(@FormParam("")StudentVO studentVO);
@POST
@Path(value="/deleteStudent")
String deleteString(@FormParam("sNo")String sNo);
@POST
@Path(value="/addStudent")
@Consumes("application/x-www-form-urlencoded; charset=UTF-8")
Response addStudent(@FormParam("")StudentVO studentVO);
}