What is the best approach for Java, Spring and Angularjs web application?

I want to create a web application using the following technologies: Maven, Java, Hibernate, Spring (core, mvc, security, data), Bootstrap 3, AngularJs. I'm wondering what works best in between. My question is how to organize the web part. I have many html pages in my application (homepage.html, login.html, usermanagement.html, profil.hml, project.html):

1. I want to use a real single page application where. I have one main file with ng-view tag and use routeProvider to switch to partial. For example, I could write the following code

    myApp.config(['$routeProvider',
      function($routeProvider) {
        $routeProvider.
          when('/', {
            templateUrl: 'partials/homepage.html',
            controller: 'HomeCtrl'
          }).
          when('/login/', {
            templateUrl: 'partials/login.html',
            controller: 'LoginCtrl'
          }).
          otherwise({
            redirectTo: '/'
          });

  }]);

      

  1. The second option is to make multiple applications with one page. In this case, each page will be rendered using Spring mvc. On each page I will have an angle adjuster. For example, the following Spring MVC controller displays the home page.

    @Controller @RequestMapping ("/") public class HomePageController {

    @RequestMapping( method = RequestMethod.GET )
    public String index() {
    
        return "homepage";
    }
    
          

    }

For the home page, I will have the configuration as:

 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: '/'
              });

      }]);

      

Thus, the page will be one-page. Thanks for reading and for your suggestions.

+3


source to share


1 answer


For the proposed stack, consider conceptually splitting your web application in Java, Hibernate, Spring frontend and AngularJS frontend, Bootstrap.

This way you can use something like Spring Boot to help you customize your backgrounds. This will create a Maven project for you with all dependencies and a nice project layout.



Then you can use any backing tools to build your AngularJS app. Yeoman is a good tool to get you started with AngularJS and Bootstrap. It also creates a Grunt build file that automates the build process for you.

Then you should only use the service endpoints in your backend content and create the entire UI in the front-end application. Then you can use Maven / Grunt to combine the two into one deployable application, or even decide to host them separately.

0


source







All Articles