Eclipse + Spring + maven Building a RESTful Web Service---need to add comments

Source: Internet
Author: User

1.Eclipse--help--new software installing the MAVEN plugin

Url:http://download.eclipse.org/technology/m2e/releases

2.Eclipse Creating Maven Project (tick create a simple project)

GroupId, Artifactid is required, the value of <groupid > and <artifactid > in Pom.xml after the project is created successfully

3. Modify Pom.xml

To add a configuration file:

<parent>
<groupid>org.springframework.boot</groupid>
<artifactId> Spring-boot-starter-parent</artifactid>
<version>1.2.2.release</version>
</parent

<dependencies>
<dependency>
<groupid>org.springframework.boot</groupid
<artifactid>spring-boot-starter-web</artifactid>
</dependency>
</ Dependencies>

<build>
<plugins>
<plugin>
<groupId> Org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-release</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-release</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

4. Add the Entity class:

public class Greeting {

Private final long ID;
Private final String content;

Public greeting (long id,string content) {
This.id = ID;
this.content = content;
}

Public long getId () {
return ID;
}

Public String getcontent () {
return content;
}


}

5. Add Controller:

@RestController
public class Greetingcontroller {

private static final String template = "hello,%s!";

Private final Atomiclong counter = new Atomiclong ();

@RequestMapping ("/greeting")
Public greeting Greeting (@RequestParam (value= "name", defaultvalue= "World") String name) {
return new Greeting (Counter.getandincrement (), String.Format (template, name));
}
}

6. Add the Project startup class:

@SpringBootApplication
public class Application {
public static void Main (string[] args) {
Springapplication.run (Application.class, args);
}
}

7. Project Start Access url:http://localhost:8080/greeting return results:

{"id": 1, "Content": "hello,world!"}



Test success: (Maven + Restful) learning phase, without comment

Eclipse + Spring + maven Building a RESTful Web Service---need to add comments

Related Article

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.