際際滷

際際滷Share a Scribd company logo
Booting Spring Data REST
願化(woniper)
leekw3747@gmail.com
http://blog.woniper.net
 REST API
 Spring Web MVC
 Spring Data JPA  Java ORM
 襯  覺り碓, 覓伎語 螻伎狩.
Modern Application
れ Client 煙
Client To Server
Server To Server
ろ語 誤壱伎 REST
API
Booting Spring Data REST
Booting Spring Data REST
Spring Data REST
REST API襯 所 襷り鍵  蠍一
 Repository 誤壱伎 襷朱 REST API 螻
轟
 Repository 誤壱伎 襷朱 REST API 螻
 Query Method : 覃 語朱 蟆 API 讌
轟
 Repository 誤壱伎 襷朱 REST API 螻
 Query Method : 覃 語朱 蟆 API 讌
 Projection : 一危  覦 れ蟆 / 螳
轟
 Repository 誤壱伎 襷朱 REST API 螻
 Query Method : 覃 語朱 蟆 API 讌
 Projection : 一危  覦 れ蟆 / 螳
 HATEOAS : MetaData  (Model, Link, Resource)
轟
Spring Data
Spring Data REST
Spring Data REST
蟆 襷れ 覲手?
襷
蟆蠍 煙
螳ロ.
@Entity
public class Board {
@Id @GeneratedValue
private Long boardId;
@Embedded
private Contents contents;
@ManyToOne(optional = false) // 襷ろ 
private Member member;
}
@Embeddable
public class Contents {
@Column(name = "title", nullable = false)
private String title; // 覈
@Lob
@Column(name = "body", nullable = false)
private String body; // 覲碁 伎
}
@Entity
public class Member {
@Id @GeneratedValue
private Long memberId;
@Column(name = "username", unique = true, nullable = false)
private String username;
@Column(name = "first_name", nullable = false)
private String firstName;
@Column(name = "last_name", nullable = false)
private String lastName;
@OneToMany(cascade = CascadeType.ALL)
private List<Board> boards = new ArrayList<>();
}
Spring MVC
@Controller
@RequestMapping("/boards")
public class BoardController {
@ResponseBody // 
@RequestMapping(method = RequestMethod.POST)
public Board post(@RequestBody Board board) {};
@ResponseBody // 譟壱
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Board get(@PathVariable("id") Long boardId) {};
@ResponseBody // 
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Board put(@PathVariable("id") Long boardId,
@RequestBody Contents contents) {};
@ResponseBody // 
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void post(@PathVariable("id") Long boardId) {};
}
Controller
@Service
@Transactional
public class BoardService {
public Board new(Board board){}; // 
public Board get(Long boardId){}; // 譟壱
public Board update(Board board){}; // 
public void remove(Long boardId){}; // 
}
Service
@Repository
interface BoardRepository
extends CrudRepository<Board, Long> {
Board save(Board board); // insert, update
Board findOne(Long boardId); // select
void delete(Long boardId); // delete
}
Repository
覦覲給螻
 貊
伎 磯Μ螳  蟆.
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {}
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {}
 REST API .
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {}
/{entity}s/{id}
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {}
/boards/1
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {}
覃螳 螻 API
POST : /boards
PUT | PATCH : /boards/{id}
GET : /boards/{id}
POST : /boards
PUT | PATCH : /boards/{id}
GET : /boards/{id}
POST : /boards
PUT | PATCH : /boards/{id}
GET : /boards
GET : /boards/{id}
POST : /boards
PUT | PATCH : /boards/{id}
DELETE : /boards/{id}
GET : /boards
蟆 API 襷り 苦伎.
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {
@RestResource(path = "starts-title")
List<Board> findByContentsTitleStartsWith(
@Param("title") String title);
}
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {
@RestResource(path = "starts-title")
List<Board> findByContentsTitleStartsWith(
@Param("title") String title);
}
/boards/search/starts-title
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {
@RestResource(path = "starts-title")
List<Board> findByContentsTitleStartsWith(
@Param("title") String title);
} ?title={}
/boards/search/starts-title
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {
@RestResource(path = "starts-title")
List<Board> findByContentsTitleStartsWith(
@Param("title") String title);
}
覈 h襦 
蟆蠍 襴ろ碁ゼ 譟壱螻 苦伎.
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {
@RestResource(path = "starts-title")
List<Board> findByContentsTitleStartsWith(
@Param("title") String title);
} /boards/search/starts-title?title=h
覈 h襦 
蟆蠍 襴ろ碁ゼ 譟壱螻 苦伎.
@RepositoryRestResource
interface BoardRepository
extends CrudRepository<Board, Long> {
@RestResource(path = "starts-title")
List<Board> findByContentsTitleStartsWith(
@Param("title") String title);
}
SELECT *
FROM board
WHERE title LIKE h%
LiveCoding!?
レ
 觜襯願 REST API 螳覦 螳
 レ 暑.
 蠍一ヾ 襦語 れ 螳. (Spring Data  蟆
)
覲伎企蟆 り .
REST API
DDD
(ORM + Database)
Spring
WEB
DATA
DATA REST
!!!
!!!
譟伎煙  覃
!!!
譟伎煙  覃
 脚ろ
!!!
譟伎煙  覃
 脚ろ
譟壱襷
.

More Related Content

Booting Spring Data REST

Editor's Notes

  1. 語. Booting Spring DATA REST 覦襯狩蟆 願化. 企 螳覦 蟆暑 4谿螳 蟲. 一れ 覦磯狩朱 觜るゼ 螳覦螻給.
  2. 覦 蠍 覦襯 j鍵 伎 REST API螳 覓伎語, Spring MVC襯 覺り, Spring Data JPA Java ORM 企慨蟇磯 覓伎語 j鍵 り碓 螳給. 覦 蟆給.
  3. 襾殊 讀 襴貅伎 覈旧 企 覈旧語 覯 危エ 覲願 螳蟆給.
  4. 1. 讀 蟲ロ 襷 企殊伎誤 蠍郁鍵れ 蟆給. 2. 蠍郁鍵れ 磯Μ螳 襷 覯 旧 覃 一危磯ゼ 譯手 覦給. 覯 碁 API 覯 襷 旧 一. 3. 企殊伎誤 蟯 覲企 覯 一危磯ゼ 譯手 覦 誤壱伎る 覲 一. 4. 蠏碁 讀 覯 旧 蠍 伎 ろ語 誤壱伎 譴 REST API襯 襷 .
  5. 螻手碓 覲企 企殊伎誤 蠍郁鍵 譬襯 襷讌 螻, 覯 蟲 觜蟲 蠍 覓語 觜讀 襦讌螻 一危 蠍一 蠏碁Μ螻 一危磯伎り讌 襦 牛 襦語 覈旧 覲 給.
  6. 讌襷 れ 蠍郁鍵螳 蟆覃伎 覯 觜伎螻, 覃 蟲 覲旧″伎螻 蠍 覓語 覃語 蠍一朱 覯襯 覿襴螻, 螳螳 覯 REST API襦 旧.
  7. 蠏碁 企蟆 ろ語 誤壱伎る 襷 REST API襯 Spring Data REST襯 牛 企至 所 觜襯願 螳ク蟆 螳覦 讌 覲願給.
  8. Spring Data REST REST API襯 所 觜襯願 襷り鍵 蠍一. 轟 Spring Data REST襯 覿 螻螳? 覃 螳語朱 覲伎覿? 企慨讌 殊企 覦襯 れ殊螻 Spring Data REST螳 覓伎語, 企至 讌 螳朱 譬蟆給.
  9. れ Spring Data REST 覈 螳讌 轟 覲願給. Spring Data 螻牛 Repository 誤壱伎 襷朱 REST API襯 襷 給.
  10. Repository 誤壱伎れ 覃 碁朱 蟆 API螳 螻給. Spring Data 覃襯 貎朱Μ 覃手 一. 貎朱Μ 覃 Spring Data 螻牛 覓碁 磯 覃覈 覃 覃覈 蠍一朱 譟壱貎朱Μ襯 襷り 譟壱貎朱Μ螳 蟆 API襦 螻給.
  11. Projection 壱一 一危磯ゼ れ蟆 螻 蠍磯レ.
  12. HATEOAS Hypermedia As The Engine Of Application State 曙. HATEOAS 襴貅伎 螳ロ 1. 一危 覈語 覃一危磯, 2. 襷覲, 3. 襴 煙 Response Body襦 蠍磯レ.
  13. 轟 伎手鍵襯 覃伎 Spring Data 伎 覈覯 瑚 蟾 る 伎 蟇 螳給. Spring Data Data 伎企ゼ 豢 襦語. 磯Μ螳 襷 jpa mongodb, redis 螳 蟲豌企れ 磯Μ螳 讌 蟲讌 螻 Spring Data 企 襷れ伎 蟲豌企ゼ 蟆 誤壱伎るゼ 螻牛.
  14. 1. Spring Data REST Spring Data API Spring Web MVC API螳 蟆壱 襦語. 2. Spring Data 一危 伎企ゼ 豢り 一. Spring Data REST 豢 一危 伎企ゼ REST API襦 螻牛 蠍一. 3. 讀 no_sql レ襯 覲企 覦襦 REST API襯 螻牛 蟆曙郁 襷 蠏碁 覩語 覲企 Spring Data REST れ レ襯 豢襯 螻 覦襦 REST API襦 蠍一.
  15. 蠏碁Μ螻 Spring Data REST JPA, Gemfire, MongoDB, Redis, Solr() 企蟆 豐 5螳讌 蠍一 讌螻 る Spring Data JPA襯 蠍一朱 る
  16. Spring MVC Spring Data REST襦 蟆 REST API襯 襷 貊襯 觜蟲企慨蟆給.
  17. 蟆 蟲 壱 UML 覲願給. 1. Member壱一 2. 蟆 Board 壱 3. 蠏碁Μ螻 蟆蠍 覈螻 覲碁 伎 蟯襴 Contents 給. 蟆蠍 煙 覦 襷 煙 螳ロ.
  18. Board 壱磯 Board襯 覲 boardId 蟆蠍 覈螻 覲碁 伎 Contents 螻. 蟆蠍 燕 Member 壱郁 襷ろ朱 れ 給.
  19. Contents 企る 覈 title 覲 覲碁 伎 body 覲螳 碁伎給.
  20. 襷讌襷朱 襯 Member 壱一. 1. memberId 覲螳 螻. 2. 貉殊朱 れ username螻 3. firstName, lastName 螻, 4. 蠏碁Μ螻 Member螳 燕 蟆蠍 襴ろ語 Board List螳 襷ろ伎給.
  21. 蠏碁覃 壱磯ゼ 蠍一朱 Spring MVC REST API襯 企至 襷讌 覲願給.
  22. BoardController boards朱 url襦 , 譟壱, , API襯 螻牛. ロ 蟲豌企 伎. 企蟆 燕 襷 覲伎襴り.
  23. 蠏碁Μ螻 BoardRepository襯 譟危 , 譟壱, , BoardService 企れ.
  24. 蟆蠍 一危磯伎れ insert, update, select, delete BoardRepository .
  25. 1. , 譟壱, , 覿覿 覦覲旧願 . 2. 貎朱Μ 襷谿螳讌螻 襦 覲伎襴 API 覿覿 覦覲旧願 .
  26. 蠏碁 Spring Data REST REST API襯 企至 襷讌 覲手? 朱蟾, 誤 覯 螻 覲願給.
  27. 給! BoardRepository 誤壱伎 襷朱 覈蟆 給. , 譟壱, , API襯 襷れ螻. 讌讌 襷れ伎讌, 磯襯 覯 覲伎襴蟆.
  28. BoardRepository襯 誤 る襴蟆給. RepositoryRestResource 誤伎 覿企 BoardRepository 誤壱伎る REST API襦 れ 蟆.
  29. url 襷ろ るΝ 朱 れ Board 壱磯 覲旧 boards螳 . 蠏碁Μ螻 id path Board 壱一 覲 Long .
  30. 企一朱 URL 襷ろ .
  31. CrudRepository interface襷 覦 企至 REST API螳 襷れ伎蟾??
  32. 1. 覦襦 覃螳 REST API襦 蠍 覓語. 2. CrudRepository interface 覃螳 , 覃れ 企 API襯 螻牛讌 危エ覲願給.
  33. 壱磯ゼ 一危磯伎れ , save 覃 蟆蠍 炎骸 螳ロ REST API螳 讌. 危願譯??
  34. findOne 覃 id襦 譟壱 螳ロ API襯 螻牛螻.
  35. findAll 覃 蟆蠍 襴ろ 譟壱 API襯 螻牛.
  36. Delete 覃 蟆蠍 API襯 螻牛.
  37. 轟 Query-Method襯 伎伎 蟆 API 所 襷 り 譯? 蟆 API 企至 襷讌 覲手?
  38. 蟆蠍 覈 轟 覓語企 蟆蠍 襴ろ 蟆 API襯 findByContentsTitleStartsWith 覃 碁朱 襷れ給.
  39. RestResource 誤伎 path襯 starts-title襦 れ覃 /boards/search/starts-title襦 url 襷ろ企.
  40. 蠏碁Μ螻 Param 誤伎 れ title url 朱誤磯 螻給.
  41. 蠏碁覃 覈 h襦 蟆蠍 襴ろ碁ゼ 蟆 蟲 り 螳螻 URL 襷れ企慨蟆給.
  42. 蠏碁覃 /boards/search/starts-title url title 朱誤磯 h襦 URL 襷れ 豌覃
  43. findByContentsTitleStartsWith 覃 Title 貉殊 like 蟆 貎朱Μ襦 一危磯ゼ 譟壱 API襦 一危磯ゼ . 螳 讌蠍蟾讌 蟲豌企ゼ 襷れ 螻 API襯 襷れ譯? 蠍郁讌螳 Spring Data REST 蠍磯蓋 覯伎給.
  44. 蠏碁 Spring Data REST襯 企至 企 讌 譟郁 れ 伎手鍵蠍磯 螻 殊企 貊 覃 覯 覲願給.
  45. レ. , 譟壱, , API襯 觜襯願 螳覦 螻 レ 曙給. 蠏碁Μ螻 Spring Data襯 蟆曙一 所 覿 給.
  46. 讌襷! 覲伎企蟆 り .
  47. 螳 レ襷 螻 讌 一. 螳 螳 Data REST 狩 蠍一 襷給. KSUG 手昭 覦蟠螻 伎手鍵 Spring Data REST襯 譬 企手 一. 蠍 所 覲願鍵 譬讌襷, 企蟆 狩 蠍一 襷る 詞.
  48. Spring Data REST襯 企 讌 螳 企瓦給.
  49. 豌 覯讌碁 譟伎煙 覃語 り 螳. 襯 れ 貉る┯ 譯朱 覃語 , 蟆一, 誤, 貎 れ 覃語 譟伎煙 覦覃 貎佒企 誤碁 覃語 譟伎煙 蠍 覓語 り 螳.
  50. 覯讌碁 脚ろ. Spring Data REST data 伎企ゼ 蠏碁襦 REST襦 蠍一企手 襷碁一. 脚ろ 一危磯伎るゼ 譟壱蟇磯 譟一伎朱 脚ろ 企慨覃 譬蟇 螳給. 蠏碁Μ螻 Spring Data REST HAL browser朱 REST Client 伎 豢螳襷朱 螻牛.
  51. 襷讌襷朱 譟壱襷 企慨蟇企一. 殊企貊 覃伎 覺る ReadOnlyPagingAndSortingRepository襯 襷れ伎 覃 蟇 螳給.
  52. 蟾讌 覦 れ伎殊 螳.