Save Many-to-Many in Spring MVC

房东的猫 提交于 2019-11-30 16:08:05

You will have to define a custom property editor for the tags property of your restaurant object on your controller.

@InitBinder
    protected void initBinder(HttpServletRequest request,
            ServletRequestDataBinder binder) throws Exception {

        super.initBinder(request, binder);

        binder.registerCustomEditor(List.class, "tags",new CustomCollectionEditor(List.class){

            @Override
            protected Object convertElement(Object element) {
                Tag tag = new Tag();

                if (element != null) {
                    Long id = Long.valueOf(element.toString());
                    tag.setId(id);
                }
                return tag;
            }
        });

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!