Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am making a similar implementation starting from this example <a href="https://github.com/xvitcoder/spring-mvc-angularjs" rel="nofollow">https://github.com/xvitcoder/spring-mvc-angularjs</a>. The main difference with the sample</p> <p>a) put all the AngularJS HTML files under webapp/WEB-INF/views</p> <p>b) have a Spring ViewResolver mapped on /views. We are using Velocity but you can you use freechart or whatever view technology.</p> <pre><code>&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"&gt; &lt;property name="resourceLoaderPath" value="/WEB-INF/views/"&gt; &lt;/bean&gt;&lt;!-- see xvitcoder sample for the complete web.xml--&gt; </code></pre> <p>c) have a Controller that respond to your HTML partial requests. The magic is that the client side URL doesn't need to match the physical folder structure. This is something lacking when you have a static html project.</p> <pre><code>@RequestMapping("dummypath/{folder}/{remainder}") public String getSomePartial(@PathVariable("folder") String folder, @PathVariable("remainder") String path) { return folder + "/" + path; } </code></pre> <p>dummpypath allows to isolate the requests for AngularJS partials (ngInclude, ngView) from other requests like servlet or REST service. The HTML files are still actually under /views/folder/path. You can do more complex stuff like computing a different view name.</p> <pre><code>&lt;div ng-include="dummypath/summary/table.html"&gt;&lt;/div&gt; </code></pre> <p>will load the views/summary/table.html file. Your ViewResolver will preprocess this file beforehand, allowing some server side fixes. </p> <p>d) Example of passing parameters to angularjs from Spring MVC. Define the query in your Spring Controller and return a html file</p> <pre><code>@RequestMapping public String getPage(@RequestParam(value="someparam", defaultValue="0") string myparam, ModelMap model){ model.addAttribute("someparam", myparam) return "index"; //index.html } </code></pre> <p>In the AngularJs controller inject $location to retrieve the parameter.</p> <pre><code>$scope.someparam = ($location.search()).someparam </code></pre> <p>Once the index is loaded, we are in Angular ecosystem! I am using this method to refresh the webpage while retaining the context. Based on the query parameter, you can load some JSON stuff or have ngSwitch put on the right partial.</p> <p>e) PROS and CONS</p> <p>PROS: simply you can't always build a complete solution with static files + REST</p> <p>CONS: testing and building the project requires extra steps. You need to bundle stuff in a WAR, testing them outside and inside. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload