In spring's configuration file, we define a bean, and spring will generate the object at startup.
<= "HelloWorld" class= "Com.game.controller.Helloworld " > </beans>
Now let's take a look at this file.
First, on the Java Resource-src, right-click New->package Build Com.game.controller build a package, then right-click on the package on the New->class, The class name is HelloWorld, and then click Finish. The project structure follows:
Let me look at the contents of Helloworld.java:
PackageCom.game.controller;Importjava.io.IOException;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping; @Controller Public classHelloworld {@RequestMapping ("/helloworld")//here control the access path in the browser specifically:/springdemo/helloworld Public voidHelloWorld (HttpServletRequest request, httpservletresponse response)throwsIOException {//Output StringResponse.getwriter (). Append ("Hello World"); }}
The HelloWorld content is simple through the Servlet output object output string "Hello World". Below we start the server and run it in the browser to see the results.
Configure the server first (Tomcat must be installed beforehand), and in Helloworld.java right-click on Run server and select our configured tomcat 8.5
Start the server:
After successful startup, open browser input http://localhost:8080/SpringDemo/helloworld:
Java Spring MVC project Build (iii)--"Hello World"