call controller method using jquery

2020-04-01 java spring model-view-controller request

I am trying to fetch an article from the db using jquery code this is the jquery function

function searchArticle(codeArticle){
    if(codeArticle){
        //alert(codeArticle);
        var detailHtml ="";


        $.getJSON("detailArticle",
                    {   
                        codeArticle: codeArticle, 
                        ajax:true   
                    },
                    function(data){
                        if(data){
                            detailHtml+= "<tr>"+
                                    "<td>"+data[0].article.codeArticle+"</td>"+
                                    "<td>1</td>"+
                                    "<td>"+data[0].prixUnitaireTTC+"</td>"+
                                    "<td>0</td>"+
                                     "</tr>";
                            $("#detailNouvelleCommande").append(detailHtml);
                        }else{
                            alert("article not found");
                        }
                    });
    }
}

and this is my controller method

@RequestMapping(value = "/detailArticle")
    @ResponseBody
    public Article getArticleByCode(String codeArticle){
        if(codeArticle == null){
            return null;
        }
        Article article = articleService.findOne("codeArticle", codeArticle);
        if(article == null){
            return null;
        }
        return article;
    }

the method selects the article from database correctly however while returning it I receive the following eror:

 java.lang.IllegalArgumentException: No converter found for return value of type: class com.stock.mvc.entity.Article
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:187)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:174)
    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:132)
    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)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)

Answers

Related