Angular调用SpringBoot的index.html该如何实现?
创始人
2024-10-24 12:01:33
0
  1. 在Spring Boot的Controller中创建返回index.html的Endpoint,如下所示:
@Controller
public class HomeController {

    @RequestMapping("/")
    public String home() {
        return "index.html";
    }
}
  1. 在Angular中创建一个Service,使用HttpClient来获取Spring Boot的Endpoint返回的index.html文件,例如:
@Injectable()
export class HomeService {

  constructor(private http: HttpClient) { }

  public getHome(): Observable {
    return this.http.get('/api/home', {responseType: 'text'});
  }
}
  1. 在Angular的Component中调用HomeService来获取index.html文件,例如:
@Component({
  selector: 'app-home',
  template: '
' }) export class HomeComponent implements OnInit { public homeHtml: string; constructor(private homeService: HomeService) { } ngOnInit() { this.homeService.getHome().subscribe( (response: string) => { this.homeHtml = response; }, (error: HttpErrorResponse) => { console.error(error); } ); } }
  1. 将Angular的index.html修改为调用Component,如下所示:

  

相关内容

热门资讯

透视科技!佛手大菠萝13道挂哪... 透视科技!佛手大菠萝13道挂哪里(透视)果然真的是有挂(详细辅助2025新版教程)1、透视辅助简单,...
热门推荐!wpk辅助器,德州局... 热门推荐!wpk辅助器,德州局hhpoker,存在挂教程(有挂辅助)这是由厦门游乐互动科技有限公司精...
透视规律!wpk模拟器(透视)... 透视规律!wpk模拟器(透视)好像真的是有挂(详细辅助wepoke教程);1、完成的残局,帮助玩家取...
一分钟揭秘!pokemmo手机... 一分钟揭秘!pokemmo手机辅助软件,hhpoker有没有外挂,揭秘教程(有挂辅助);小薇(透视辅...
透视辅助!pokemmo修改器... 透视辅助!pokemmo修改器手机版(透视)确实是有挂(详细辅助黑科技教程)运辅助工具,进入游戏界面...
教学盘点!wepoker怎么破... 教学盘点!wepoker怎么破解游戏,sohoo poker辅助器,爆料教程(有挂技巧);1.wep...
透视游戏!wepoker免费钻... 透视游戏!wepoker免费钻石(透视)果然真的有挂(详细辅助详细教程);进入游戏-大厅左侧-新手福...
一分钟了解!werplan外挂... 一分钟了解!werplan外挂,德普之星私人局辅助器,揭秘教程(有挂教程)是一款可以让一直输的玩家,...
辅助透视!aapoker安装包... 辅助透视!aapoker安装包怎么使用(透视)一直真的有挂(详细辅助2025新版教程);1、在ai机...
重大消息!aapoker免费透... 重大消息!aapoker免费透视脚本,大菠萝免费辅助,揭秘教程(有挂技巧)1、不需要AI权限,帮助你...