package pms.web.json;


import org.springframework.http.HttpStatus;

import org.springframework.web.bind.annotation.MatrixVariable;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseStatus;

import org.springframework.web.bind.annotation.RestController;


import pms.domain.Tour;

import pms.service.TourService;


@RestController

@RequestMapping("/tour")

public class TourController {

    

    TourService tourService;

    

    public TourController(TourService tourService) {

        this.tourService = tourService;

    }


    @RequestMapping("add")

    @ResponseStatus(HttpStatus.CREATED)

    public void add(Tour tour) throws Exception {

        tourService.add(tour);

    }

    

    @RequestMapping("delete")

    //@ResponseStatus(HttpStatus.OK) // 응답 상태 코드 값의 기본은 "200(OK)" 이다.

    public void delete(@RequestParam("lno") int no)/*@Request저장소로 부터 값을 꺼내서 값을 전달해 준다. 만약 @RequestParam("no") int no처럼 파라미터 명과 매개 변수명이 같으면 @RequestParam을 생략할 수 있다.*/ throws Exception {

        tourService.delete(no);

    }

    

    @RequestMapping("list{page}")

    public Object list(

            @MatrixVariable(defaultValue="1") int pageNo,

            @MatrixVariable(defaultValue="3") int pageSize) {        

        return tourService.list(pageNo, pageSize);

    }

    

    @RequestMapping("update")

    @ResponseStatus(HttpStatus.OK) // 기본 값이 OK 이다. 

    public void update(Tour tour) throws Exception {

        tourService.update(tour);

    }

    /tour/1

    @RequestMapping("{no}")

    public Tour view(@PathVariable int no) throws Exception {

        return tourService.get(no); //DAO에서 selectOne으로 선언해놨기 때문에 get은 selectOne으로 동작한다

    }


}


JSON 데이터를 출력하는 페이지 컨트롤러 생성

기본적으로 컨트롤러는 사용자의 요청을 받아 서비스를 호출하는 역할로 쓰인다. 

RestController는 텍스트 데이터를 반환한다. 

'프로그래밍 > Spring' 카테고리의 다른 글

서비스 인터페이스  (0) 2018.07.22
domain&dto&vo  (0) 2018.07.21
Posted by kingroad

블로그 이미지
개발자를 꿈꾸는 코린이 입니다
kingroad

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.7
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함