1.Eclipse --> help --> new software 安装Maven插件

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

2.Eclipse 创建 Maven project (勾选 create a simple project)

groupId ,artifactId 为必填项,项目新建成功后对应 pom.xml 中的 <groupId >和<artifactId >中的值

3.修改pom.xml

文档查考:http://maven.apache.org/pom.html#The_Basics

添加配置文件:

<parent>
<groupId>org.springframework.boot</groupId><!--This is generally unique amongst an organization or a project-->
<artifactId>spring-boot-starter-parent</artifactId><!--The artifactId is generally the name that the project is known by-->
<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.添加实体类:

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.添加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.添加项目启动类:

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

7.项目启动访问url :http://localhost:8080/greeting 返回结果:

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

测试成功:(Maven + Restful)学习阶段,暂且不加注释

转载于:https://www.cnblogs.com/summer-arvin/p/4309546.html

Eclipse + Spring + maven Building a RESTful Web Service ---需要添加注释相关推荐

  1. 【转】Spring 4.x实现Restful web service

    http://my.oschina.net/yuyidi/blog/352909 首先我们还是跟之前一样,创建一个maven项目,不过因为Spring Restful web service是基于Sp ...

  2. Building a Restful Web Service(最好的Spring入门教程 --来自Spring官网的Guides)

    搭建一个Restful Web服务 本文档将引导你用Spring搭建一个"Hello,World!"Restful Web服务. 你要搭建的是什么? 你将搭建一个Web服务,这个服 ...

  3. Spring起步(一)Building a RESTful Web Service

    http://spring.io/guides/gs/rest-service/ 先放链接. 这个很小很小的一个功课,我却遇到了各种各样的奇葩错误,折腾了两天才弄好. 想要开始的话,需要一些准备工具 ...

  4. gradle第二天(Building a RESTful Web Service)

    1.创建项目project: 在项目下用命令:mkdir -p src/main/java/hello/ 创建路径 src/main/java/hello/ 2.在项目下添加文件: (1)在src/m ...

  5. Building a RESTful Web Service

    http://spring.io/guides/gs/rest-service/ Should shutdown tomcat service first , and then java -jar * ...

  6. spring3创建RESTFul Web Service

    spring 3支持创建RESTFul Web Service,使用起来非常简单.不外乎一个@ResponseBody的问题. 例如:后台controller: 做一个JSP页面,使用ajax获取数据 ...

  7. Apache CXF实现Web Service(3)——Tomcat容器和不借助Spring的普通Servlet实现JAX-RS(RESTful) web service...

    起步 参照这一系列的另外一篇文章: Apache CXF实现Web Service(2)--不借助重量级Web容器和Spring实现一个纯的JAX-RS(RESTful) web service 首先 ...

  8. spring boot demo( 获取一个RESTful web service)

    Consuming a RESTful Web Service spring demo中给的接口是  http://gturnquist-quoters.cfapps.io/api/random. 返 ...

  9. Java RESTful Web Service实战(第2版)

    Java核心技术系列 Java RESTful Web Service实战 (第2版) 韩陆 著 图书在版编目(CIP)数据 Java RESTful Web Service实战 / 韩陆著. -2版 ...

最新文章

  1. 利用Python让你的命令行像坤坤一样会打篮球
  2. 【Storm】storm安装、配置、使用以及Storm单词计数程序的实例分析
  3. 【万字长文】详解Python时间处理模块-datetime
  4. [译] APT分析报告:03.OpBlueRaven揭露APT组织Fin7/Carbanak(上)Tirion恶意软件
  5. 找到特定ip地址 修改ip_您如何找到网站的IP地址?
  6. 实例4:python
  7. 在pycharm中自定义模板代码,快速输出固定代码块
  8. TimeJot – Last Time 改名,新增中文界面、数字属性,还是那个时间线管理神器[Android]
  9. HBase基本操作-java api
  10. 数字猜谜游戏python_Python Tkinter教程系列02:数字猜谜游戏
  11. Linux开机启动过程(15):start_kernel()->rcu_init()初始化
  12. iOS NSString URLencode
  13. 了解RxJava以及如何在Android应用中使用它
  14. 由jar文件生成jad文件
  15. Adams_2019_x64
  16. python+selenium实现QQ空间的登录
  17. ODIN SNN处理器
  18. Java POI word常用方法 在Cell插入子表格
  19. 计算机怎么求标准偏差,如何计算Excel标准偏差?您必须知道这两个技巧
  20. 中科院文新:深度学习入门基础与学习资源

热门文章

  1. linux ora 00911,python – DatabaseError:ORA-00911:无效字符
  2. AlexNet做文档布局分析 (版面分析)数据集
  3. c语言程序设计考场排座位,“听说学霸座位是这个?”老师揭秘排座,真正的C位其实在这里……...
  4. python列表快速排序_python 实现快速排序
  5. Singleton in java
  6. BZOJ 2679 [Usaco2012 Open]Balanced Cow Subsets
  7. Module not found: Error: Can't resolve 'XXX' in 'XXXX'
  8. 一片关于Bootstarp4的文章
  9. MySql 使用规范推荐(转)
  10. centos/linux下的安装Nginx