gradle第二天(Building a RESTful Web Service)
1.创建项目project:
在项目下用命令:mkdir -p src/main/java/hello/
创建路径 src/main/java/hello/
2.在项目下添加文件:
(1)在src/main/java/hello/下添加三个java文件,分别是:
Application.java
1 package hello; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6 @SpringBootApplication 7 public class Application { 8 public static void main(String[] args) { 9 SpringApplication.run(Application.class, args); 10 } 11 }
Greeting.java
1 package hello; 2 public class Greeting { 3 private final long id; 4 private final String content; 5 public Greeting(long id, String content) { 6 this.id = id; 7 this.content = content; 8 } 9 public long getId() { 10 return id; 11 } 12 public String getContent() { 13 return content; 14 } 15 }
GreetingController.java
1 package hello; 2 3 import java.util.concurrent.atomic.AtomicLong; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RequestParam; 6 import org.springframework.web.bind.annotation.RestController; 7 8 @RestController 9 public class GreetingController { 10 private static final String template = "Hello, %s!"; 11 private final AtomicLong counter = new AtomicLong(); 12 13 @RequestMapping("/greeting") 14 public Greeting greeting( 15 @RequestParam(value = "name", defaultValue = "World") String name) { 16 return new Greeting(counter.incrementAndGet(), String.format(template,name)); 17 } 18 }
(2)在project目录下添加build.gradle文件:
1 buildscript { 2 repositories { 3 mavenCentral() 4 } 5 dependencies { 6 classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE") 7 } 8 } 9 10 apply plugin: 'java' 11 apply plugin: 'eclipse' 12 apply plugin: 'idea' 13 apply plugin: 'spring-boot' 14 15 jar { 16 baseName = 'gs-rest-service' 17 version = '0.1.0' 18 } 19 20 repositories { 21 mavenCentral() 22 } 23 24 sourceCompatibility = 1.7 25 targetCompatibility = 1.7 26 27 dependencies { 28 compile("org.springframework.boot:spring-boot-starter-web") 29 testCompile("junit:junit") 30 } 31 32 task wrapper(type: Wrapper) { 33 gradleVersion = '2.3' 34 }
3.gradle build
建立gradle环境
4.gradle run
运行gradle服务
转载于:https://www.cnblogs.com/zhmnda/p/4790834.html
gradle第二天(Building a RESTful Web Service)相关推荐
- 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/ 先放链接. 这个很小很小的一个功课,我却遇到了各种各样的奇葩错误,折腾了两天才弄好. 想要开始的话,需要一些准备工具 ...
- Building a RESTful Web Service
http://spring.io/guides/gs/rest-service/ Should shutdown tomcat service first , and then java -jar * ...
- Eclipse + Spring + maven Building a RESTful Web Service ---需要添加注释
1.Eclipse --> help --> new software 安装Maven插件 url:http://download.eclipse.org/technology/m2e/r ...
- Java RESTful Web Service实战(第2版)
Java核心技术系列 Java RESTful Web Service实战 (第2版) 韩陆 著 图书在版编目(CIP)数据 Java RESTful Web Service实战 / 韩陆著. -2版 ...
- Java RESTful Web Service实战
编者按: InfoQ开设栏目"品味书香",精选技术书籍的精彩章节,以及分享看完书留下的思考和收获,欢迎大家关注.本文节选自韩陆著<Java RESTful Web Servi ...
- 使用JAX-RS创建RESTful Web Service
guice resteasy http://www.cnblogs.com/ydxblog/p/7891224.html http://blog.csdn.net/withiter/article/d ...
- 在GlassFish应用服务器上创建并运行你的第一个Restful Web Service【翻译】
前言 本人一直开发Android应用,目前Android就业形势恶劣,甚至会一路下滑,因此决定学习服务器开发.采用的语言是java,IDE是Intellij,在下载Intellij的同时看到官网很多优 ...
- WCF实现RESTFul Web Service
共同学习了前面一些概念,终于开始正题了哈.RESTful的Web Service调用直观,返回的内容容易解析.这里先会描述一个简单的场景--Web Service提供一个方法来搜索个人信息,传入人名, ...
最新文章
- 关于MySQL count(distinct) 逻辑的另一个bug_
- 链表/模拟 - 两数相加
- Pycharm上Django的使用 Day8
- 如何备份 Outlook Express 项
- 校园招聘 - 比较容易的面试题
- 第三方服务-阿里云视频点播服务java服务端SDK相关代码
- ear的英语怎么念_Dog是“狗”,ear是“耳朵”,Dog ear真不是“狗耳朵”
- 官方版sublime Text3汉化和激活注册码
- 如何实施基本的“长轮询”?
- FlashDevelop打包IOS应用教程
- HTTP 304状态码
- Cain嗅探工具的https数据捕获
- ltspice导入spice模型_LTspice 怎么自建 MOSFET 模型
- JAVA练习216-整数的英语表示
- java通过FTP连接到NAS服务器
- 用四叉树管理散布在平面上的对象
- Leetcode总结之Union Find
- 【不知道发啥】Win7网页版使用方法
- Python 实现哥德巴赫猜想
- Linux下批量重命名文件或文件夹(rename命令)
热门文章
- MongoDB复制集(Replication Sets)介绍
- Python中time模块详解
- Windows Azure真实案例:GoGrid -托管提供商拓展了服务方案,通过云平台吸引更多客户...
- struts2.xml详解
- 手机项目,html抬头,HTMLCSS学习笔记(二十)-- 移动端项目准备工作
- java有无参数求长方形的周长面积_用java面向对象思想编程求长方形的周长和面积...
- 训练神经网络最应该注意什么才能让显卡最大限度的发挥性能
- opencv-python将一个视频切成n份视频
- AJPFX实列判断一个字符串是不是对称字符串
- python3-泊松分布