레이블이 roo인 게시물을 표시합니다. 모든 게시물 표시
레이블이 roo인 게시물을 표시합니다. 모든 게시물 표시

2012-09-25

Spring MVC Controller 의 REST scaffold

spring roo 가 제공하는 것을 약간 수정하여 나만의 scaffold로...
* roo는 update 경로가 좀 다르고
* list에서 spring data의 Pageable을 사용함.

http://java.dzone.com/articles/restful-standard-resolved 도 참고하자.


@RequestMapping
public String list(@PageableDefaults(pageNumber = 0, value = Config.PAGE_SIZE) Pageable pageable, Model model) {
}

@RequestMapping(method = RequestMethod.POST)
public String create(@Valid MyObj obj, BindingResult bindingResult, Model model, HttpServletRequest httpServletRequest) {
}

@RequestMapping(params = "form")
public String createForm(Model model) {
}

@RequestMapping(value = "/{obj}", method = RequestMethod.PUT)
public String update(@Valid @ModelAttribute("obj") MyObj obj, BindingResult bindingResult, Model model, HttpServletRequest httpServletRequest) {
}

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public View remove(@PathVariable Long id) {
}

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView show(@PathVariable Long id, Model model) throws Exception {
}

2012-09-22


roo의 service는 aggregate repository 같다. domainTypes에 entity만 지정해주면 그에 해당하는 repository들을 모두 엮어 준다.  그렇다면 하나의 entity가 여러 service에 지정될 수도 있다. 하지만 이건 좋지 않은 것 같다. 서로 역할이 달라야 할 service들이 하나의 entity에 대한 operation들을 중복해서 가지게 되니까. 각 service가 처리하는 entity들은 관련 영역별로 구분하여 모아주는 것이 좋지 않을까. 물론 service라는 것이 지정된 entity만 처리할 수는 없을 것이다. 그럴 때는 domainTypes에 해당 entity를 지정하는 것보다는 그 entity의 repository를 DI 받도록 하자.

AspectJ가 주입된 메소드, 필드를 못찾는다 싶을 때에는 Markers -> Java Problems 를 보자. 여기에는 진짜 문제만 나타난다. 한번은 이클립스에 아주 많은 에러가 있는 듯 표시하지만 Java Problems에는 단 2개의 문제만 있었다. 그 2개의 문제만 해결했더니 모든 에러가 사라졌음.