際際滷

際際滷Share a Scribd company logo
Booting Spring Data REST
for SLiPP 17.06.14
願化(woniper)
leekw3747@gmail.com
http://blog.woniper.net
 REST API
 Spring Web MVC
 Spring Data JPA  Java ORM
 襯  覺り碓, 覓伎語 螻伎狩.
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!?
Deep Dive Spring Data REST
Spring Web MVC
Booting spring data rest for SLiPP
Booting spring data rest for SLiPP
Booting spring data rest for SLiPP
Booting spring data rest for SLiPP
@RepositoryRestController
Booting spring data rest for SLiPP
RepositoryController
OPTIONS : /
HEAD : /
GET : /
RepositoryEntityController
OPTIONS : /{entity}
HEAD : /{entity}, /{entity}/{id}
GET : /{entity}, /{entity}/{id}
POST : /{entity}
PUT : /{entity} /{id}
PATCH : /{entity} /{id}
DELETE : /{entity} /{id}
RepositoryPropertyReferenceController
GET : /{entity}/{id}/{property}, /{entity}/{id}/{property}/{propertyId}
DELETE : /{entity}/{id}/{property}, /{entity}/{id}/{property}/{propertyId}
PATCH: /{entity}/{id}/{property}
PUT : /{entity}/{id}/{property}
POST : /{entity}/{id}/{property}
RepositorySearchController
OPTIONS : /{entity}/search, /{entity}/search/{search}
HEAD : /{entity}/search, /{entity}/search/{search}
GET : /{entity}/search, /{entity}/search/{search}
 蟾覲願鍵
 extends HandlerMapping, HandlerAdapter
 extends @RepositoryRestController
 extends HandlerMethodArgumentResolver
レ
 觜襯願 REST API 螳覦 螳
 レ 暑.
 譴   .
覲伎企蟆 り .
REST API
DDD
(ORM + Database)
Spring
WEB
DATA
DATA REST
 讌覓
 DTO 企至 磯?
 HATEOAS 覦 朱?
 覲伎 企至 譯?
 Spring Boot襷 ?
!!!
!!!
譟伎煙  覃
!!!
譟伎煙  覃
 脚ろ
!!!
譟伎煙  覃
 脚ろ
譟壱襷
!!!
譟伎煙  覃
 脚ろ
譟壱襷 
prototype
Q & A
.

More Related Content

Booting spring data rest for SLiPP

Editor's Notes

  • #2: 語. Booting Spring DATA REST 覦襯狩蟆 願化. 企 螳覦 蟆暑 4谿螳 蟲. 一れ 覦磯狩朱 觜るゼ 螳覦螻給.
  • #3: 覦 蠍 覦襯 j鍵 伎 REST API螳 覓伎語, Spring MVC襯 覺り, Spring Data JPA Java ORM 企慨蟇磯 覓伎語 j鍵 り碓 螳給. 覦 蟆給.
  • #4: る 譯殊 ろ豌
  • #5: 覲伎覿?
  • #6: れ Spring Data REST 覈 螳讌 轟 覲願給. Spring Data 螻牛 Repository 誤壱伎 襷朱 REST API襯 襷 給.
  • #7: Spring Data Query Method 蟆 API
  • #8: れ Response Body
  • #9: HATEOAS Hypermedia As The Engine Of Application State 曙. 覃 一危
  • #10: れ 蠍一 一危 伎 豢 朱 JPA(jdbc -> hibernate -> JPA -> Data JPA)
  • #11: Spring Data + Spring MVC 一危磯ゼ 蠏碁襦 REST API襦
  • #12: 讌 螳ロ 蠍一
  • #13: Spring MVC 蟆 Spring Data REST 蟆 觜蟲
  • #14: Member 蟆 Board 覲碁 Contents
  • #15: Member entity 襷ろ
  • #16: Contents 企る 覈 title 覲 覲碁 伎 body 覲螳 碁伎給.
  • #18: 蠏碁覃 壱磯ゼ 蠍一朱 Spring MVC REST API襯 企至 襷讌 覲願給.
  • #19: , 譟壱, , API 旧 貊
  • #20: 蠏碁Μ螻 BoardRepository襯 譟危 , 譟壱, , BoardService 企れ.
  • #21: 蟆蠍 一危磯伎れ insert, update, select, delete BoardRepository .
  • #22: , 譟壱, , (CRUD) 覿覿 覦覲 貎朱Μ, API
  • #23: Spring Data REST? 殊襷!
  • #24: ! 觜蟲 磯
  • #25: BoardRepository襯 誤 る襴蟆給. RepositoryRestResource 誤伎 覿企 BoardRepository 誤壱伎る REST API襦 れ 蟆.
  • #26: Entity 覲旧覈 == URL 覲 == resource
  • #27: 企一朱 URL 襷ろ .
  • #28: CrudRepository interface襷 覦 企至 REST API螳 襷れ伎蟾??
  • #29: Method == API襦
  • #30: Save == , Save == POST, PUT, PATCH
  • #31: findOne 覃 id襦 譟壱 螳ロ API襯 螻牛螻.
  • #32: findAll == get list
  • #33: Delete 覃 蟆蠍 API襯 螻牛.
  • #34: Query method襦 蟆 API
  • #35: findByContentsTitleStartsWith == query method Query method == 蟆 API 蟆 API == 蟆蠍 覈 轟 覓語企 襴ろ
  • #36: RestResource 誤伎 path襯 starts-title襦 れ覃 /boards/search/starts-title襦 url 襷ろ企.
  • #37: 蠏碁Μ螻 Param 誤伎 れ title url 朱誤磯 螻給.
  • #38: 蠏碁覃 覈 h襦 蟆蠍 襴ろ碁ゼ 蟆 蟲 り 螳螻 URL 襷れ企慨蟆給.
  • #39: 蠏碁覃 /boards/search/starts-title url title 朱誤磯 h襦 URL 襷れ 豌覃
  • #40: findByContentsTitleStartsWith 覃 Title 貉殊 like 蟆 貎朱Μ襦 一危磯ゼ 譟壱 API襦 一危磯ゼ . 螳 讌蠍蟾讌 蟲豌企ゼ 襷れ 螻 API襯 襷れ譯? 蠍郁讌螳 Spring Data REST 蠍磯蓋 覯伎給.
  • #41: 蠏碁 Spring Data REST襯 企至 企 讌 譟郁 れ 伎手鍵蠍磯 螻 殊企 貊 覃 覯 覲願給.
  • #42: ろ襷 貂 殊企 貊蟾讌. Deep Dive 豢螳 Spring Data REST ろ豌 る
  • #43: ろ襷 貂 殊企 貊蟾讌. Deep Dive 豢螳 Spring Data REST ろ豌 る
  • #44: る 伎 DispatcherServlet == FrontController pattern ViewResolver
  • #45:
  • #46: Default 豢豌 : ろ襷 MVC 襦蠏碁覦 (觜螳豈)
  • #47: Data REST 豈
  • #48: 企 蟲 Contorller るジ Controller @RepositoryRestController 譬襯
  • #49: @RepositoryRestController Diagram
  • #55: レ. , 譟壱, , API襯 觜襯願 螳覦 螻 レ 曙給. 蠏碁Μ螻 Spring Data襯 蟆曙一 所 覿 給.
  • #56: 讌襷! 覲伎企蟆 り .
  • #57: 螳 レ襷 螻 讌 一. 螳 螳 Data REST 狩 蠍一 襷給. KSUG 手昭 覦蟠螻 伎手鍵 Spring Data REST襯 譬 企手 一. 蠍 所 覲願鍵 譬讌襷, 企蟆 狩 蠍一 襷る 詞.
  • #59: Spring Data REST襯 企 讌 螳 企瓦給.
  • #60: 豌 覯讌碁 譟伎煙 覃語 り 螳. 襯 れ 貉る┯ 譯朱 覃語 , 蟆一, 誤, 貎 れ 覃語 譟伎煙 覦覃 貎佒企 誤碁 覃語 譟伎煙 蠍 覓語 り 螳.
  • #61: 覯讌碁 脚ろ. Spring Data REST data 伎企ゼ 蠏碁襦 REST襦 蠍一企手 襷碁一. 脚ろ 一危磯伎るゼ 譟壱蟇磯 譟一伎朱 脚ろ 企慨覃 譬蟇 螳給. 蠏碁Μ螻 Spring Data REST HAL browser朱 REST Client 伎 豢螳襷朱 螻牛.
  • #62: 襷讌襷朱 譟壱襷 企慨蟇企一. 殊企貊 覃伎 覺る ReadOnlyPagingAndSortingRepository襯 襷れ伎 覃 蟇 螳給.
  • #63: 襷讌襷朱 譟壱襷 企慨蟇企一. 殊企貊 覃伎 覺る ReadOnlyPagingAndSortingRepository襯 襷れ伎 覃 蟇 螳給.
  • #64: 蟾讌 覦 れ伎殊 螳.
  • #65: 蟾讌 覦 れ伎殊 螳.