Add the mock functionality returned after parsing the JSON file under Server Classpath in SPRINGMVC:
Import Java.io.filenotfoundexception;import java.io.ioexception;import java.io.inputstream;import Java.net.URL; Import Java.net.urlconnection;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.web.bind.annotation.pathvariable;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.requestmethod;import Org.springframework.web.bind.annotation.restcontroller;import Com.fasterxml.jackson.databind.jsonnode;import Com.fasterxml.jackson.databind.ObjectMapper, @RestController @requestmapping ("/mock") public class Mockcontroller {@ Requestmapping (value = "/{module}/{action}", method = requestmethod.post) public jsonnode mockcontent (@PathVariable Str ing module, @PathVariable String action, httpservletrequest request, httpservletresponse response) {Jso Nnode actualobj = null; InputStream FIS = null; try {ClassLoader Ctxloader = ThreaD.currentthread (). Getcontextclassloader (); URL Resurl = Ctxloader.getresource (action + ". JSON"); URLConnection resconn = Resurl.openconnection (); Resconn.setusecaches (FALSE); FIS = Resconn.getinputstream (); StringBuilder builder = new StringBuilder (); int ch; while ((ch = fis.read ())! =-1) {builder.append ((char) ch); } objectmapper mapper = new Objectmapper (); Actualobj = Mapper.readtree (builder.tostring ()); } catch (FileNotFoundException e) {e.printstacktrace (); } catch (IOException e) {e.printstacktrace (); } finally {if (FIS! = null) {try {fis.close (); } catch (IOException e) {}}} return actualobj; }}
Other types of support can also be added, such as string data, or something else. Since the Springmvc rest interface uses the JSON converter by default, it needs to be converted to the corresponding JSON format
SPRINGMVC support for adding mock JSON