首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.ui.Model]:指定的类是一个接口

org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.ui.Model]:指定的类是一个接口
EN

Stack Overflow用户
提问于 2019-03-12 12:45:51
回答 1查看 1.4K关注 0票数 0

我用的是弹力靴。我的dao实现是:

代码语言:javascript
复制
public void saveDetails(Proforma_Invoice proforma) {
    Session session = null;
    Transaction tx = null;
    try {
        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        session.saveOrUpdate(proforma);
        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isOpen())
            session.flush();
        if (session != null && session.isOpen())
            session.close();
    }
}

我的控制器是:

代码语言:javascript
复制
 @RequestMapping(value = "/enquiry", method = RequestMethod.GET)
    public ModelAndView getEnquiryScreen(Model model, Item_entity item, Integer item_code, vendor_entity vendor) {
        System.out.println("Controller is starting..");
        ModelAndView mav = new ModelAndView("enquiry_Screen");
        return mav;
    }

    @RequestMapping(value = "/enquiry", method = RequestMethod.POST)
    public ModelAndView demo(@ModelAttribute("enquiry") Model model, Item_entity item, Integer item_code,
            vendor_entity vendor, Proforma_Invoice proforma) {
        System.out.println("Controller is starting..");
        ModelAndView mav = new ModelAndView("enquiry_Screen"););
        return mav;
    }

当我保存数据时使用了这些,然后我得到了错误:

代码语言:javascript
复制
2019-03-12 09:45:34.352 ERROR 7256 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ui.Model]: Specified class is an interface] with root cause

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ui.Model]: Specified class is an interface

请看这个问题。帮我解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-12 13:40:23

您正在尝试混合使用Model作为控制器参数和使用@ModelAttribute。当您有一个包含来自传入请求的参数的form对象,并且希望@ModelAttribute将这些参数复制到该对象的实例中时,就会使用Spring。要么将表单对象用于POST映射(这是一个好主意),要么删除注释以使用Model

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55114343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档