其余API POST内容类型'application / json; charset = UTF-8'不支持

时间:2018-12-03 08:33:06

标签: java spring rest post java-ee

这是我剩下的职位管理员

@RestController
@RequestMapping(path="/entry")
public class EntryController {
    @RequestMapping(method=RequestMethod.POST)
        @ResponseBody
        public void addEntry(@RequestBody Entry entry){
            service.save(entry);
        }
}

我在用soapui执行请求时,我在日志中收到此错误

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:237)
        at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:150)
        at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128)
        at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
        at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:160)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963

enter image description here

1 个答案:

答案 0 :(得分:0)

这是我的入门课程

package pl.primigenius.tsprimi.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author Kamil
 */

@Entity
@Table(name="Entry")
@NamedQueries({
    @NamedQuery(name="Entry.findAllEntries", query="SELECT e FROM Entry e"),
    @NamedQuery(name="Entry.findEntryByID", query="SELECT e FROM Entry e WHERE e.id = :ID"),
    @NamedQuery(name="Entry.findByUserID", query="SELECT e FROM Entry e WHERE e.user.id = :userID"),
    @NamedQuery(name="Entry.findByProjectID", query="SELECT e FROM Entry e WHERE e.project.id = :projectID"),
})
public class Entry extends BaseEntityAudit {

    @ManyToOne
    @JoinColumn(name="USER_ID", nullable=false)
    @JsonBackReference
    private User user;

    @ManyToOne
    @JoinColumn(name="PROJECT_ID", nullable=false)
    @JsonBackReference
    private Project project;

    @Column(name="HOURS", nullable=false)
    private BigDecimal hours;

    @Column(name="COMMENT")
    private String comment;

    @Column(name="POST_DATE")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date postDate;

    public User getUser() {
        return user;
    }

    public Project getProject() {
        return project;
    }

    public BigDecimal getHours() {
        return hours;
    }

    public String getComment() {
        return comment;
    }

    public Date getPostDate() {
        return postDate;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public void setHours(BigDecimal hours) {
        this.hours = hours;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public void setPostDate(Date postDate) {
        this.postDate = postDate;
    }





}