猿问

扩展阔叶默认管理控制器

我想为管理端(broadleaf 框架)创建自己的控制器,它扩展了 AdminBasicEntityController。有我的控制器代码:


    public class AdminArticleController extends AdminBasicEntityController {


    @Autowired

    private ArticleService articleService;


    @Override

    public String addEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute("entityForm") EntityForm entityForm, BindingResult result) throws Exception {

        return super.addEntity(request, response, model, pathVars, entityForm, result);

    }


    @Override

    public String saveEntityJson(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable("id") String id, @ModelAttribute("entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {

        return super.saveEntityJson(request, response, model, pathVars, id, entityForm, result, ra);

//        articleService.updateArticleEntity();

    }

}

我还在 AdminServletConfig 文件中添加了下一个代码:


@Bean

public AdminBasicEntityController adminBasicEntityController() {

    return new AdminArticleController();

}


慕田峪9158850
浏览 59回答 1
1回答

开满天机

你很亲近!要覆盖现有的 Broadleaf bean,请务必使用注释中声明的 bean 名称。将您的 bean 命名为“blAdminBasicEntityController”,如下所示:@Beanpublic AdminBasicEntityController blAdminBasicEntityController() {&nbsp; &nbsp; return new AdminArticleController();}您看到的错误是由于有两个具有相同映射的 bean。发生这种情况是因为 AdminBasicEntityController 带有注释@Controller("blAdminBasicEntityController"),这意味着它将被组件扫描拾取并创建一个名为 的 bean blAdminBasicEntityController。由于 AdminArticleController 扩展了 AdminBasicEntityController,一旦创建了 AdminArticleController bean,AdminBasicEntityController 中的每个映射都会有 2 个映射。解决方案是覆盖 Broadleaf bean,而不是添加一个额外的。
随时随地看视频慕课网APP

相关分类

Java
我要回答