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