阔叶覆盖控制器方法

时间:2017-06-03 09:49:20

标签: broadleaf-commerce

我是关于阔叶的新人。

我有问题,我想隐藏在admin中删除订单的方法:

我创建了控制器:

public class NewOrderController extends AdminBasicEntityController {

    private static final Logger LOGGER = Logger.getLogger(NewOrderController.class);

    protected static final String SECTION_KEY = "order";

    @Override
    protected String getSectionKey(Map<String, String> pathVars) {
        if (super.getSectionKey(pathVars) != null) {
            return super.getSectionKey(pathVars);
        }
        return SECTION_KEY;
    }

    @Override
    @RequestMapping(
        value = {"/{id}/delete"},
        method = {RequestMethod.POST}
    )
    public String removeEntity(HttpServletRequest request, HttpServletResponse response, Model model, Map<String, String> pathVars, String id, EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {

        LOGGER.info("wywołanie nadpisane metody: " + NewOrderController.class.toString());
        return "String";
    }


}
textContext-admin.xml

中的

添加:

它一直称它为未覆盖的方法。

1 个答案:

答案 0 :(得分:1)

创建控制器时,bean必须位于servlet上下文中,而不是根上下文中。如果要修改applicationContext-admin.xml,那么实际上是将bean添加到根上下文中。

将您的bean添加到applicationContext-servlet-admin.xml或向<component-scan>添加新的applicationContext-servlet-admin.xml条目以扫描您的新bean。

还有一件事:您可能不想覆盖整个AdminBasicEntityController,看起来您只想覆盖/order/*方法。在这种情况下,您应该使用@Controller为控制器添加注释,并为您的部分键添加@RequestMapping,如下所示:

@Controller
@RequestMapping("/" + SECTION_KEY)
public class NewOrderController extends AdminBasicEntityController {

    private static final Logger LOGGER = Logger.getLogger(NewOrderController.class);

    protected static final String SECTION_KEY = "order";

    @Override
    protected String getSectionKey(Map<String, String> pathVars) {
        if (super.getSectionKey(pathVars) != null) {
            return super.getSectionKey(pathVars);
        }
        return SECTION_KEY;
    }

    @Override
    @RequestMapping(
        value = {"/{id}/delete"},
        method = {RequestMethod.POST}
    )
    public String removeEntity(HttpServletRequest request, HttpServletResponse response, Model model, Map<String, String> pathVars, String id, EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {

        LOGGER.info("wywołanie nadpisane metody: " + NewOrderController.class.toString());
        return "String";
    }

}