Spring文檔整理
阿新 • • 發佈:2017-05-15
支持 import 功能 created hub template private build png
一:
1.進入學習的地方
二:進入第一個地方
1.Building a RESTful Web Service
2.第一個內容
what you will build:
講述了實現的目標是:
1.通過仿真連接,可以返回json
2,通過改變連接的詢問字符串,改變參數,返回被覆蓋的字段。
3.第二個內容
what you need
講述完成這些功能需要的軟件支持:
4.第三個內容
how to complete the guide
可以使用github下載代碼
#進入新建的目錄
#進入鏈接,進行下載
#進入要求的目錄
下面是步驟5。
5.第四塊內容
create response repensentation class
創建一個類,為id和content進行數據訪問的平臺。
#將initial工程導入IDEA中
#創建類Greeting.java
1 package hello; 2 3 /** 4 * Created by Administrator on 2017/5/15. 5 */ 6 public class Greeting { 7 private final long id; 8 private finalString content; 9 public Greeting(long id, String content) { 10 this.id = id; 11 this.content = content; 12 } 13 public long getId() { 14 return id; 15 } 16 public String getContent() { 17 return content; 18 } 19 }
#有jackson JSON將類整理實例化到json中
6.第五塊內容
create a resource controller
書寫控制層
1 package hello; 2 3 import org.springframework.web.bind.annotation.RequestMapping; 4 import org.springframework.web.bind.annotation.RequestParam; 5 import org.springframework.web.bind.annotation.RestController; 6 7 import java.util.concurrent.atomic.AtomicLong; 8 9 /** 10 * Created by Administrator on 2017/5/15. 11 */ 12 @RestController 13 public class GreetingController { 14 private static final String template = "Hello, %s!"; 15 private final AtomicLong counter = new AtomicLong(); 16 17 @RequestMapping("/greeting") 18 public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { 19 return new Greeting(counter.incrementAndGet(), 20 String.format(template, name)); 21 } 22 }
Spring文檔整理