繁体   English   中英

@PathVarible即使在接口中声明也可以工作吗?

[英]Does @PathVarible work even when declared in an interface?

我已经使用接口对Controller进行了一些抽象。

-问题是@PathVariable似乎无法在实现中使用。

- 请帮忙。 这里Controller.java

public interface Controller<ENTITY extends Entity>
{

    @RequestMapping(value = "/", method = RequestMethod.GET)
    default public void process(final Model model)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/new", method = RequestMethod.GET)
    default public void processNew(final Model model)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/{id}/show", method = RequestMethod.GET)
    default public void processShow(final Model model, @PathVariable Long id)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
    default public void processEdit(final Model model, @PathVariable Long id)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/{id}/drop", method = RequestMethod.GET)
    default public void processDrop(final Model model, @PathVariable Long id)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    default public void processCreate(@Valid @ModelAttribute ENTITY entity, BindingResult result, SessionStatus sessionStatus)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    default public void processUpdate(@Valid @ModelAttribute ENTITY entity, BindingResult result, SessionStatus sessionStatus)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    default public void processDelete(@Valid @ModelAttribute ENTITY entity, BindingResult result, SessionStatus sessionStatus)
    {
        throw new UnsupportedOperationException("Operation not yet supported !");
    }

}

...这里是ProjetController.java并请求@PathVariable不起作用的地方

@Controller
@RequestMapping("/projects")
public class ProjectController implements Controller<Project>
{
    ...
    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
    ...
    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
    ...
    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
    ...
}

对于映射在我不知道的实现中不起作用的问题,一切似乎都很好。

关于界面上的注释,它们没有任何作用。 映射已过时,因为您在接口上设置的注释不会应用于实现类。

另一方面,它们也不会干扰,因为映射始终针对具体的实现方法进行映射,如果在调试级别进行设置,则应在启动时在日志中看到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM