javascript - 如何将角度代码与 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)。
解决方案
您不会将 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
推荐阅读
- sql-server - 在 SQL Server 中恢复具有特定登录权限的数据库
- php - 如何定位数组值 - php xml
- java - 资源颜色android的返回类型?
- office365 - Office 365 加载项侧边栏/任务窗格的名称
- c++ - [Boost::ext].SML:在操作中访问 SM 和依赖项
- awk - 如何使用 AWK 将 CSV 文件转换为 TOML 哈希表
- java - 将主要用户从一个 Spring Boot 微服务传递到另一个 Spring Boot 微服务
- spss - 以 SPSS 长格式折叠数据
- ios - SWIFTUI:防止在 TextField 中按下返回键时键盘关闭
- php - 在 php 中编写可变产品 (woocommerce)