我想使用以下技术开发Web应用程序:Maven,Java,Hibernate,Spring(核心,mvc,安全性,数据),Bootstrap 3,AngularJs。我想知道两者之间最好的方法是什么。我的问题是有关如何组织Web部件的。我的应用程序中有很多html页面(homepage.html,login.html,usermanagement.html,profil.hml,project.html):
1.我想在哪里使用真正的单页应用程序。我有一个带有ng-view标签的主文件,并使用routeProvider切换到局部文件。例如,我可以编写以下代码
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/homepage.html',
controller: 'HomeCtrl'
}).
when('/login/', {
templateUrl: 'partials/login.html',
controller: 'LoginCtrl'
}).
otherwise({
redirectTo: '/'
});
}]);
我的第二个选择是制作多个单页应用程序。在这种情况下,将使用spring mvc渲染每个页面。在每个页面中,我将有一个angularjs控制器。例如,以下Spring MVC控制器呈现主页。
@Controller
@RequestMapping(“ /”)
公共类HomePageController {
@RequestMapping( method = RequestMethod.GET )
public String index() {
return "homepage";
}
}
对于主页,我将配置为:
myhomePageApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'nothing to display',
controller: 'HomeCtrl'
}).
when('/contact/', {
// display contact info in a div on home page
templateUrl: 'partials/contact.html',
controller: 'LoginCtrl'
}).
otherwise({
redirectTo: '/'
});
}]);
因此它的页面将是一个单页面应用程序。
感谢您的阅读和建议。
最佳答案
对于建议的堆栈,请考虑将Web应用程序从概念上划分为Java,Hibernate,Spring后端和AngularJS,Bootstrap前端。
这样,您可以使用类似Spring Boot的方法来帮助您设置后端。这将为您创建一个具有所有依赖项和良好项目布局的Maven项目。
然后,您可以使用任何可用于创建AngularJS应用程序的前端脚手架工具。 Yeoman是帮助您入门AngularJS和Bootstrap的好工具。它还会创建一个Grunt构建文件,该文件会自动为您完成构建过程。
然后,您应该仅在后端中实现服务端点,并在前端应用程序中创建整个UI。然后,您可以使用Maven / Grunt将这两者组合为一个可部署的应用程序,甚至可以决定分别托管它们。