Spring MVC and Angularjs

I'm currently trying to learn Angular JS , but first I want to set up my environment using Spring mvc .

At the moment I only want to work with rest, but I have a doubt that the best way to place resoucres in Spring mvc

My simple application has this script:

 my-simple-app: src main java resources webapp resources WEB-INF 

If I want to put the app folder from angular-seed , what is the best place to put it?

I tried to insert src/webapp/resources/app , but then I need to move the html files to WEB-INF?

How is your skeleton in your angular -js spring mvc applications?

What is the best way to do a redirect to app/index.html ? to the welcome file and then only work with angularjs $routeproviders ?

Thanks!

+8
java angularjs spring-mvc maven
source share
4 answers

As far as I understand, your Front End technology is Angualar JS, and Back End technology is Spring MVC.

I am a Front End developer, and therefore I can provide you with guidelines for the structure of your HTML, CSS, and Javascript.

Here are my recommendations:

  • Communication mode between the front and rear end: JSON (strictly follow the MVC pattern)

  • File location: all your Front End files should be in the WEB-INF folder with this structure:

    • WEB-INF/Assets : all your JavaScript files, JavaScript libraries, images, CSS, etc. should be here. You can open a separate folder. Each type of resource is inside.

    • WEB-INF/JSP : All of your JSPs should be placed here. Since Angular's greatest strength is a one-page application, you can create one JSP on the main page and put them here.

    • WEB-INF/HTML : all static resources that will be inserted into the JSP using <ng-view> or <ng-include> can be placed here

Hope this helps!

+8
source share

The easiest way to get all the files in the angular-seed/app directory and copy them to the src/main/webapp directory. After copying these files, you can redeploy the application and run the sample.

Most servlet containers will include index.html as their default welcome file. If you do not, you can add this configuration to web.xml <welcome-file-list> .

The WEB-INF directory is intended for web resources that should not be displayed directly on the Internet. web.xml is an example of a file that should not be exposed to remote users. In this case, it is safe to display all application resources directly on the Internet; therefore, you do not need to host resources under WEB-INF.

+5
source share

In the first step of Angular + Spring, I used this list of tutorials:

https://www.youtube.com/watch?v=Sc2atFv_h_I

It contains 12 great videos that explain how to step by step. It contains information on installation, configuration, architecture best practices, etc.

+2
source share

I recommend this structure for your project:

 my-simple-app: src main java controller MySpringCtr.java models Person.java House.java *.java webapp WEB-INF resources css style.css *.css js angularCtr.js *.js pages index.jsp *.jsp mvc-dispatcher-servlet.xml web.xml 

I found a beginner tutorial that explains step by step how to combine SpringMVC and AngularJS, you can find a tutorial and full code in this blog I hope this will be useful :)

0
source share

All Articles