我构建了 Angular 项目。将 dist 文件夹粘贴到 src/main/resources/static,现在我可以从 Controller 调用 index.html 文件。但问题是 (localhost:4200/homePage?empId=1234) 是起始页面无法从 Controller 调用此页面。 代码如下(Spring Controller )
@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 应用程序将负责定义 REST Web 服务并为请求提供服务,无论是 Angular 还是任何其他技术。因为 REST 是独立于平台的。
Angular 和 Spring Boot 应用的集成方式有很多种,具体可以引用下面的文章。
https://www.devglan.com/spring-boot/spring-boot-angular-deployment
关于javascript - 如何将 Angular 代码与 spring boot 集成?如何从 Controller 调用 Angular 特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53411910/