我试图用Thymeleaf和嵌入式Tomcat创建一个非常简单的SpringBoot1.3.3Web应用程序,使用OpenUI5作为客户端javascript库.,但我似乎无法让OpenUI5加载数据sap-ui资源。这是可能的吗?
我首先进入start.spring.io,生成一个具有Web和Thymeleaf依赖项的maven项目,然后添加一个带有XML的基本OpenUI5结构。我学习了以下教程:
最后,我得到了以下项目结构:
root
├── src
│ ├── main
│ │ ├── java
│ │ │ └── myPackage
│ │ │ ├── controllers
│ │ │ │ └── LandingPageController.java
│ │ │ └── Application.java
│ │ └── resources
│ │ ├── application.properties
│ │ ├── static
│ │ │ └── webapp
│ │ │ └── view
│ │ │ └── App.view.xml
│ │ └── templates
│ │ └── landingPage.html
│ └── test
│ └── java
│ └── myPackage
│ └── ApplicationTests.java
│
└── pom.xml尽管这些教程基本上都是标准的,但为了完整起见,我将包括我的源代码:
Application.java:
package myPackage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}LandingPageController.java:
package myPackage.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/")
public class LandingPageController {
@RequestMapping(method=RequestMethod.GET)
public String redirect() {
return "landingPage";
}
}landingPage.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<title>SAPUI5 Walkthrough</title>
<script
id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"sap.ui.demo.wt": "./"
}'>
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.xmlview({
viewName : "sap.ui.demo.wt.view.App"
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>App.view.xml:
<mvc:View
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Text text="Hello World"/>
</mvc:View>我的application.properties文件是空的,pom.xml正是由弹簧起爆生成的。
我认为问题在于landingPage.html中的这一行,但除了“./”之外,我不知道还能写什么:
data-sap-ui-resourceroots='{
"sap.ui.demo.wt": "./"
}在OpenUI5教程中,我能够完成第3步的工作;然而,一旦我必须在XML文件中定义视图,OpenUI5库就无法找到它。我不知道还能把App.view.xml文件放在哪里,我认为静态文件夹下的任何地方都可以.
我不确定这是否与我使用嵌入式Tomcat这一事实有关,但我希望这可以使用嵌入式Tomcat。
有什么建议可以让我这样做吗?
发布于 2016-05-06 12:36:31
我不熟悉Spring或任何提到的Java框架,但我可以尝试帮助您使用resourceRoots。
有了这个设置,您可以告诉OpenUI5框架,在哪里找到特定的资源。
"sap.ui.demo.wt": "./"的设置意味着可以在当前页/文件的同一个目录中找到以sap.ui.demo.wt开头的所有内容。任何进一步的.<something>都意味着具有该名称的子文件夹。
您可以定义相对于您的html文件或绝对的resourceRoots,例如:
"sap.ui.demo.wt": "/resources/static/webapp"
在这种情况下,将在sap.ui.demo.wt.view.App中找到(或至少查找)名为/resources/static/webapp/view/App.view.xml的视图。
https://stackoverflow.com/questions/37063494
复制相似问题