首页 > 解决方案 > 如何将角度代码与 Spring Boot 集成?如何从控制器调用特定的角度页面?

问题描述

我建立了角度项目。将 dist 文件夹粘贴到 src/main/resources/static 中,现在我可以从控制器调用 index.html 文件。但问题是 (localhost:4200/homePage?empId=1234) 是起始页面无法从控制器调用此页面。代码如下(弹簧控制器)

@RequestMapping("/homePage")
public String testMethod() {
    return "/index.html";

}

index.html 是这样的

<!doctype html>
<html lang="en" dir="ltr">
<head>
   <meta charset="utf-8">
   <title>TestApp</title>
   <base href="/homePage">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!--link rel="icon" type="image/x-icon" href="favicon.ico"-->
  <link rel="stylesheet" 
 href="http://localhost:8080/homePage/styles.2e25b77c70b5269b3e1c.css"> 
  </head>
  <body>
    <app-root></app-root>
   <script type="text/javascript" 
    src="http://localhost:8080/homePage/runtime.ec2944dd8b20ec099bf3.js"> 
   </script>
     <script type="text/javascript" 

  src="http://localhost:8080/homePage/polyfills.b58e3c18bf0ef2973262.js"> 
  </script>
   <script type="text/javascript" 
   src="http://localhost:8080/homePage/main.b4ad8245c5085d925098.js"> 
   </script>
 </body>
</html

想去这个页面(localhost:4200/homePage?empId=1234)。

标签: javascriptjavaspringangular

解决方案


您不会将 Angular js 与 Spring Boot 的东西混合使用。Angular 是关于前端(客户端)的。定义 UI 并与 Spring Boot 应用程序通信以获取、插入或更新资源。

Spring Boot Application 将负责定义 REST Web 服务并以 Angular 或任何其他技术为请求提供服务。因为 REST 是独立于平台的。

有很多方法可以集成 Angular 和 Spring Boot 应用程序,您可以参考下面的文章了解更多详细信息。

https://www.devglan.com/spring-boot/spring-boot-angular-deployment


推荐阅读