Eclipse + Spring + maven Building a RESTful Web Service ---需要添加注释
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 ---需要添加注释相关推荐
- 【转】Spring 4.x实现Restful web service
http://my.oschina.net/yuyidi/blog/352909 首先我们还是跟之前一样,创建一个maven项目,不过因为Spring Restful web service是基于Sp ...
- Building a Restful Web Service(最好的Spring入门教程 --来自Spring官网的Guides)
搭建一个Restful Web服务 本文档将引导你用Spring搭建一个"Hello,World!"Restful Web服务. 你要搭建的是什么? 你将搭建一个Web服务,这个服 ...
- Spring起步(一)Building a RESTful Web Service
http://spring.io/guides/gs/rest-service/ 先放链接. 这个很小很小的一个功课,我却遇到了各种各样的奇葩错误,折腾了两天才弄好. 想要开始的话,需要一些准备工具 ...
- gradle第二天(Building a RESTful Web Service)
1.创建项目project: 在项目下用命令:mkdir -p src/main/java/hello/ 创建路径 src/main/java/hello/ 2.在项目下添加文件: (1)在src/m ...
- Building a RESTful Web Service
http://spring.io/guides/gs/rest-service/ Should shutdown tomcat service first , and then java -jar * ...
- spring3创建RESTFul Web Service
spring 3支持创建RESTFul Web Service,使用起来非常简单.不外乎一个@ResponseBody的问题. 例如:后台controller: 做一个JSP页面,使用ajax获取数据 ...
- 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 首先 ...
- spring boot demo( 获取一个RESTful web service)
Consuming a RESTful Web Service spring demo中给的接口是 http://gturnquist-quoters.cfapps.io/api/random. 返 ...
- Java RESTful Web Service实战(第2版)
Java核心技术系列 Java RESTful Web Service实战 (第2版) 韩陆 著 图书在版编目(CIP)数据 Java RESTful Web Service实战 / 韩陆著. -2版 ...
最新文章
- 利用Python让你的命令行像坤坤一样会打篮球
- 【Storm】storm安装、配置、使用以及Storm单词计数程序的实例分析
- 【万字长文】详解Python时间处理模块-datetime
- [译] APT分析报告:03.OpBlueRaven揭露APT组织Fin7/Carbanak(上)Tirion恶意软件
- 找到特定ip地址 修改ip_您如何找到网站的IP地址?
- 实例4:python
- 在pycharm中自定义模板代码,快速输出固定代码块
- TimeJot – Last Time 改名,新增中文界面、数字属性,还是那个时间线管理神器[Android]
- HBase基本操作-java api
- 数字猜谜游戏python_Python Tkinter教程系列02:数字猜谜游戏
- Linux开机启动过程(15):start_kernel()->rcu_init()初始化
- iOS NSString URLencode
- 了解RxJava以及如何在Android应用中使用它
- 由jar文件生成jad文件
- Adams_2019_x64
- python+selenium实现QQ空间的登录
- ODIN SNN处理器
- Java POI word常用方法 在Cell插入子表格
- 计算机怎么求标准偏差,如何计算Excel标准偏差?您必须知道这两个技巧
- 中科院文新:深度学习入门基础与学习资源
热门文章
- linux ora 00911,python – DatabaseError:ORA-00911:无效字符
- AlexNet做文档布局分析 (版面分析)数据集
- c语言程序设计考场排座位,“听说学霸座位是这个?”老师揭秘排座,真正的C位其实在这里……...
- python列表快速排序_python 实现快速排序
- Singleton in java
- BZOJ 2679 [Usaco2012 Open]Balanced Cow Subsets
- Module not found: Error: Can't resolve 'XXX' in 'XXXX'
- 一片关于Bootstarp4的文章
- MySql 使用规范推荐(转)
- centos/linux下的安装Nginx