简体   繁体   English

将Angular 7与现有Java应用程序集成

[英]Integrating Angular 7 with existing Java Application

I am new to angular. 我是新手。 My current application is build in Java with JSP using YUI library. 我当前的应用程序是使用YUI库在Java和JSP中构建的。 In our application we have multiple tabs. 在我们的应用程序中,我们有多个选项卡。 Is it possible to switch to Angular 7 with same application for one or two tabs initially or we need to start with fresh project. 最初是否有可能使用一个或两个选项卡使用相同的应用程序切换到Angular 7,或者我们需要从新项目开始。

Please suggest. 请提出建议。

Yes, it is doable, as Angular can bootstrap itself from a JSP page. 是的,这是可行的,因为Angular可以从JSP页面进行引导。 It can be a great way to keep your current application running while transitioning to Angular. 这是在过渡到Angular时保持当前应用程序运行的好方法。 This way, you need less maintenance of the old tabs as they can removed quicker, while the tabs that stay in JSP can continue working. 这样,您可以减少对旧选项卡的维护,因为它们可以更快地删除,而保留在JSP中的选项卡可以继续工作。

To get started, include the Angular application root and all bundles somewhere in the JSPs of the tabs being replaced. 首先,将Angular应用程序根目录和所有捆绑软件包括在要替换的选项卡的JSP中。

<app-root></app-root>

<!-- Angular must load AFTER the app-root selector for bootstrapping  -->
<% if( request.getHeader("Host").equals("localhost:4200") ) { %>
  <!-- dev bundles, to allow the normal angular workflow on localhost -->
  <script src="inline.bundle.js"></script>
  <script src="polyfills.bundle.js"></script>
  <script src="styles.bundle.js"></script>
  <script src="vendor.bundle.js"></script>
  <script src="main.bundle.js"></script>
<% } else { %>
  <!-- production bundles -->
  <script src="inline.bundle.js?ver=${maven.build.timestamp}"></script>
  <script src="polyfills.bundle.js?ver=${maven.build.timestamp}"></script>
  <script src="main.bundle.js?ver=${maven.build.timestamp}"></script>
<% } %>

This assumes you build your java project using maven, so turn off the file versioning ng build does and let maven handle the version naming (to avoid cache problems in when releasing versions). 这假定您使用maven来构建Java项目,因此请关闭ng build进行的文件版本控制,然后让maven处理版本命名(以避免发布版本时出现缓存问题)。 Otherwise you'd have to figure out a way to insert the Angular generated file names into your JSPs for every build. 否则,您将不得不想出一种方法来将每个生成的Angular生成的文件名插入到JSP中。

ng build --prod --output-hashing none

Once the app-root is bootstrapped it can be moved using other javascript, as long as you make sure it is not removed from the DOM. 一旦引导了应用程序根目录,只要您确保没有将其从DOM中删除,就可以使用其他JavaScript将其移动。

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

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