Spring-boot VAADIN 应用程序中的 RequestMapping

RequestMapping in Sprint-boot VAADIN application

我有一个 Spring-boot VAADIN 应用程序,主要 类 如下

申请Class

@SpringBootApplication
public class MySpringBootApplication {

    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class, args);
    }
}

VAADIN-UI Class

@Theme("valo")
@SpringUI
public class MyAppUI extends UI {

    @Autowired
    private SpringViewProvider viewProvider;

    @Override
    protected void init(VaadinRequest vaadinRequest) {

        final VerticalLayout mainLayout = new VerticalLayout();
        setContent(mainLayout);

        Navigator navigator = new Navigator(this, mainLayout);
        navigator.addProvider(viewProvider);
    }
}

VAADIN-视图Class

@SpringView(name = "")
public class MyAppView extends VerticalLayout implements View {

    @PostConstruct
    void init() {
        // Some logic here
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
        // Some logic here
    }
}

目前,应用程序在根 URL 中处理请求,即 http://localhost:8080/。但我希望应用程序在 http://localhost:8080/<parameter_value> 提供参数时处理请求。我怎样才能做到这一点?

在这两种情况下我必须执行的逻辑是相同的,即我希望 MyAppView 处理根 URL 请求和具有参数值的请求。

VAADIN 的getUI().getPage().getLocation().getPath() 方法可用于从URL 中获取参数值。这将给出 URL 中 '/' 的所有内容。示例代码如下:

VAADIN-视图Class

@SpringView(name = "")
public class MyAppView extends VerticalLayout implements View {

    @PostConstruct
    void init() {
        // Some logic here
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
       // Remove spaces and also initial '/' in the path
       String uriParamValue = getUI().getPage().getLocation().getPath().trim().substring(1);
       // Do processing with uriParamValue
    }
}