与Spring MVC的AngularJS [英] AngularJS with Spring-mvc

查看:86
本文介绍了与Spring MVC的AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近碰到AngularJS来了。我是一个Java Web开发。我想与Spring的MVC框架一起使用AngularJS。但我需要一些基本的基础(教程)开始。

I recently came across AngularJS. I am a java web developer. I want to use AngularJS along with Spring-MVC framework. But I need some basic foundation (tutorial) to start with.

我知道AngularJS的基本的东西,但如何将它与Spring的MVC集成。由于大部分时间是春季的自我恢复部分JSP(S),我们将它们添加使用JSP的包括,而AngularJS预计JSON数据的大部分时间。

I know about the basic stuff of AngularJS, but how to integrate it with Spring-MVC. As most of the time spring it self return partial jsp(s), and we add them using jsp-include, while AngularJS expects JSON data most of the time.

推荐答案

两种情况:


  1. 您架构完整的客户端:在这种情况下,整合是很自然的。 Spring MVC的暴露你的服务为REST(JSON / XML)和AngularJS消耗你的JSON客户端应用程序。这里的.war应用程序(Spring MVC的)必须在servlet容器(例如Tomcat)的部署和您的客户端应用程序可以在同一台服务器或类似的Nginx或Apache HTTP服务器进行部署。

  1. Your architecture is full client-side: In this case the integration is very natural. Spring MVC exposes your service as a REST (JSON/XML) and your client application with AngularJS consumes your JSON. Here the .war application (Spring MVC) must be deployed in a servlet container (e.g. Tomcat) and your client application can be deployed in the same server or in a HTTP server like Nginx or Apache.

您想保留在服务器端生成页面并只使用AngularJS一些DOM操作让你的code必须在相同的.war部署(在WEB-INF /文件夹中)。

You want to keep page generation in the server-side and only use AngularJS for some DOM manipulation so your code must be deployed in the same .war (inside the WEB-INF/ folder).

在混合并不总是一个好主意,这两种方法。您可以尝试 Thymeleaf 留在服务器端的页面生成,并在同一时间有模板,可测试性和清洁查看code。

Mixing the two approaches in not always a good idea. You can try Thymeleaf to stay in server-side page generation and at the same time have templating, testability and clean View code.

这篇关于与Spring MVC的AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆