Java object to JS object
1. First use Jackson to convert the object to a JSON string
Objectmapper objectmapper = new Objectmapper ();
String json = objectmapper.writevalueasstring (obj); Obj is the object to be passed
2. Use Model.addattribute ("JSON", JSON) in the controller to upload the JSON string to the foreground
3. Then do the following in the foreground (these two quotes are important)
var jsonstr = '${json}'
Use Json.parse (); Convert JSON to JS object
obj = Json.parse (jsinfo);
// We can print to the console and look at this object.
Console.log (Jsninfo);
List of Java objects to JS arrays (array)
You just have to turn obj in the 1th step into list<t>.
Objectmapper objectmapper = new Objectmapper ();
String json = objectmapper.writevalueasstring (orderlist); OrderList to List<order>
Java nested object to JS object
You just need to turn obj in the 1th step into a map.
Objectmapper objectmapper = new Objectmapper ();
String JSON = objectmapper.writevalueasstring (map); Map is the map type, key is the property name, value is the referenced object
Springmvc value (object or string) to the foreground JS