* Moved Accessing Spring MVC objects model in JavaScript

This commit is contained in:
dupirefr
2020-02-09 11:11:04 +01:00
parent e703f71ada
commit 29c8b8bf0d
9 changed files with 3 additions and 3 deletions
@@ -13,7 +13,6 @@ This module contains articles about Spring Web MVC in Spring Boot projects.
- [Display RSS Feed with Spring MVC](https://www.baeldung.com/spring-mvc-rss-feed)
- [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao)
- [Setting Up Swagger 2 with a Spring REST API](https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api)
- [Accessing Spring MVC Model Objects in JavaScript](https://www.baeldung.com/spring-mvc-model-objects-js)
- [Using Spring ResponseEntity to Manipulate the HTTP Response](https://www.baeldung.com/spring-response-entity)
- [Spring Bean Annotations](https://www.baeldung.com/spring-bean-annotations)
- More articles: [[next -->]](/spring-boot-mvc-2)
@@ -1,12 +0,0 @@
package com.baeldung.accessparamsjs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
@@ -1,32 +0,0 @@
package com.baeldung.accessparamsjs;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
/**
* Sample rest controller for the tutorial article
* "Access Spring MVC Model object in JavaScript".
*
* @author Andrew Shcherbakov
*
*/
@RestController
public class Controller {
/**
* Define two model objects (one integer and one string) and pass them to the view.
*
* @param model
* @return
*/
@RequestMapping("/index")
public ModelAndView thymeleafView(Map<String, Object> model) {
model.put("number", 1234);
model.put("message", "Hello from Spring MVC");
return new ModelAndView("thymeleaf/index");
}
}
@@ -1,29 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Access Spring MVC params</title>
<script src="/js/jquery.js"></script>
<script src="/js/script-async.js"></script>
<script src="/js/script-async-jquery.js"></script>
<script>
var number = [[${number}]];
var message = "[[${message}]]";
</script>
</head>
<body>
Number=
<span th:text="${number}" th:remove="tag"></span>
<br /> Message=
<span th:text="${message}" th:remove="tag"></span>
<h2>Data from the external JS file (due to loading order)</h2>
<div id="number-ext"></div>
<div id="message-ext"></div>
<h2>Asynchronous loading from external JS file (plain JS)</h2>
<div id="number-async"></div>
<div id="message-async"></div>
<h2>Asynchronous loading from external JS file (jQuery)</h2>
<div id="number-async-jquery"></div>
<div id="message-async-jquery"></div>
</body>
<script src="/js/script.js"></script>
</html>
File diff suppressed because one or more lines are too long
@@ -1,6 +0,0 @@
$(function() {
var node1 = document.createTextNode("message = " + message);
var node2 = document.createTextNode("number = " + number);
document.getElementById('message-async-jquery').append(node1);
document.getElementById('number-async-jquery').append(node2);
});
@@ -1,6 +0,0 @@
window.onload = function() {
var node1 = document.createTextNode("message = " + message);
var node2 = document.createTextNode("number = " + number);
document.getElementById('message-async').append(node1);
document.getElementById('number-async').append(node2);
};
@@ -1,4 +0,0 @@
var node1 = document.createTextNode("message = " + message);
var node2 = document.createTextNode("number = " + number);
document.getElementById('message-ext').append(node1);
document.getElementById('number-ext').append(node2);