1. Opening-springboot Environment construction

Source: Internet
Author: User

Originally learning Strurs2, although feel also quite good, but also have some inconvenient place: 1. The model binding must declare the member variable of the corresponding model in the action; 2. The interface for external invocation in action must be clearly specified; 3. To declare a whole bunch of views; 4. When using AJAX, you also declare the Get method of the corresponding data in the action, such as to add a lot of things to the code in order to use the STRUTS2 framework, which usually leads to many code in the action or to add a lot of action classes, not so concise. With spring MVC, you can not only greatly reduce the configuration, but also non-intrusive to provide the use of various functions, instead of using AJAX only on the corresponding method with @responsebody annotations can be identified; the model is automatically bound to the parameters, Even the request of the fragment in the URL can be bound to the entry by @pathvariable, providing a direct check-in session, request and other features, using a word-cool. and learned springboot after the discovery incredibly can develop procedures, springboot advocate "Agreement first", so long as the springboot rules, you can greatly reduce the configuration, and the use of various convenience of SPRINGMVC can greatly accelerate the development of the progress. This series of blog is to use Springboot to build a personal blog site, record the development process of the various problems faced, hoping to read people can be helpful. The first is to build the skeleton of the project, as follows:
1. Create a MAVEN project and select Maven-archetype-quickstart as the project template, as follows:

2. Because the JDK for a project created by Maven defaults to 1.5, the JDK is modified to the corresponding version in the build path:

3. Add Springboot dependency, the Pom.xml file is as follows:

1 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"2 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">3   <modelversion>4.0.0</modelversion>4 5   <groupId>Com.lvniao</groupId>6   <Artifactid>Blog</Artifactid>7   <version>1.0</version>8   <Packaging>Jar</Packaging>9 Ten   <name>Blog</name> One   <URL>http://maven.apache.org</URL> A  -   <Properties> -         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> the     </Properties> -     <Parent>   -         <groupId>Org.springframework.boot</groupId>   -         <Artifactid>Spring-boot-starter-parent</Artifactid>   +         <version>1.4.3.RELEASE</version>   -         <RelativePath/>   +     </Parent>   A  at     <Dependencies>   -         <Dependency>   -             <groupId>Org.springframework.boot</groupId>   -             <Artifactid>Spring-boot-starter-web</Artifactid>   -         </Dependency>   -     </Dependencies>   in    -     <Build>   to         <Plugins>   +             <plugin>   -                 <groupId>Org.springframework.boot</groupId>   the                 <Artifactid>Spring-boot-maven-plugin</Artifactid>   *             </plugin>   $         </Plugins>  Panax Notoginseng     </Build>   - </Project>
Pom.xml

4. Modify the App class and add the Spirngboot Project launch code:

1 Package Com.lvniao.blog;2 3 import org.springframework.boot.SpringApplication;4 import org.springframework.boot.autoconfigure.SpringBootApplication;5 import org.springframework.web.bind.annotation.RequestMapping;6 import Org.springframework.web.bind.annotation.RestController;7 8 @RestController9 @SpringBootApplicationTen Public class APP One { A @RequestMapping ("/") - Public String Index () { - return "App.index"; the     } -      - Public static void Main (string[] args) -     { + Springapplication.run (App.class, args); -     } +}
App.java

In the code above, the method return value in the @restcontroller declaration controller is not processed by the view resolution, but is returned directly to the user, while @springbootapplication declares that the class is Springboot's startup class ; Springapplication.run (App.class, args) in the main method to start the springboot frame; the address of the URL that invokes the index interface method via @requestmapping ("/") Because the @restcontroller annotation class is used, the string returned by index is returned directly to the client;
5. Configure the startup class in the Run configuration:

6. Run the project in Java application type:

The output of the index method can be seen by using the: localhost:8080 address in the browser after the project is started:

This way, the side completes the first task.

1. Opening-springboot Environment construction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.