My first spring boot program (Spring boot learning Note II)

Source: Internet
Author: User

The first spring boot program

Written in front: In view of the extensive details and knowledge of the spring annotations and the SPRINGMVC configuration, we will go directly to spring boot learning after learning comprehension and will be understood again when using annotations and other relevant knowledge points in subsequent learning. To run the first spring boot is particularly straightforward, with idea containing the spring boot boot, create a new spring boot project directly.

Attention:

1, the first new spring boot project, maven will download a large number of dependencies to the local, so particularly slow, patient waiting or with the domestic maven borne (Baidu, I waited half an hour to download complete ~ ~)

2, I checked the Web components in the new process, so the original pom file will be dependent on the Spring-boot-starter-web component, of course, there is a need to tick other.

3, temporarily can't afford to, anyway online tutorial a lot

I. Introduction of the following Pom.xml file

The initialization project is finished, the following configuration appears in the Pom, only two points are mentioned here:

1, Spring-boot-starter-parent

This is a special starter that is used to provide relevant MAVEN default dependencies, and after using it, we can omit the <version> tag from the usual dependency packages.

2, Spring boot really can simplify the configuration

Because we rely on Spring-boot-starter-web, Maven automatically relies on the underlying jar packages that all Web projects require, including spring core jar packages, Tomcat-related jar packages, and so on.

2. Run our first spring boot program

1, yes, can now run, do not need any other configuration

2. Write a Hello world (to demonstrate simplicity, we no longer create a new controller and write code directly in the Portal class)

@RestController
@SpringBootApplication
public class Learnspringbootapplication {

@RequestMapping ("/")
Index () {
"Hello Spring Boot";
}

Main (string[] args) {
Springapplication. run (learnspringbootapplication. class, args);
}
}

Brief introduction:

1, the entrance class is sure to find it, is the project name plus the application

2, @RestController: If you have some understanding of SPRINGMVC, must have seen the controller this annotation, is to identify a control, Rescontroller is the collective of @controller and @responsebody.

The role of Responsebody again: @responsebody means that the return result of the method is written directly to the HTTP response body. Typically used when retrieving data asynchronously, after using @requestmapping, the return value

usually resolves to the jump path, plus @responsebody after the return result will not be resolved to the jump path, but directly written to the HTTP response body. For example, the asynchronous acquisition of JSON data, plus @responsebody, will return directly to the

Back to JSON data. (Baidu a bit, deeply agree).

3. Visit http://localhost:8080/

So there is no problem, we successfully ran the first spring boot project. If you have not contacted Springmvc's classmates suggest reading a book or teaching video or blog, a preliminary understanding of SPRINGMVC layered design concept, go to GitHub to clone a project to run a look.

I began to write a blog, but also for beginners, if wrong please point out that I will improve.

My first spring boot program (Spring boot learning Note II)

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.