【问题标题】:RequestMapping in Sprint-boot VAADIN applicationSpring-boot VAADIN 应用程序中的 RequestMapping
【发布时间】:2016-08-01 15:43:49
【问题描述】:

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

应用程序类

@SpringBootApplication
public class MySpringBootApplication {

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

VAADIN-UI 类

@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-视图类

@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 请求和带有参数值的请求。

【问题讨论】:

  • 视图按其名称打开

标签: spring-boot vaadin vaadin7


【解决方案1】:

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

VAADIN-视图类

@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
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 2023-02-07
    • 2020-06-27
    • 2023-02-03
    • 2022-01-06
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多