RequestMapping在Sprint-boot VAADIN应用程序中

时间:2016-08-01 15:43:50

标签: spring-boot vaadin vaadin7

我有一个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-View 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请求和具有参数值的请求。

1 个答案:

答案 0 :(得分:0)

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

VAADIN-View 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
    }
}