Java

자바 Rest api

NaHyungMin 2020. 7. 6. 17:51
package com.package.superpayrestapi.controller;

import lombok.Getter;
import lombok.Setter;
import org.springframework.web.bind.annotation.*;
import util.Singleton;

@RestController
@RequestMapping("/helloworld")
public class HelloController {

    @GetMapping(value = "/string")
    public String helloworldString() {
        return "helloworld";
    }

    @GetMapping(value = "/json")
    public Hello helloworldJson() {
        Hello hello = new Hello();
        hello.message = "helloworld";
        return hello;
    }

    @RequestMapping(value="/string/{text}")
    public String helloworldText(@PathVariable(value="text") String name) {
        return "text : " + name;
    }

    @PostMapping(value = "/jsonPost")
    public String helloworldPost(@RequestParam(value = "userName", required = true) String userName){
        return userName;
    }

    @Setter
    @Getter
    public static class Hello {
        private String message;
    }
}

가장 기본적인 get, post와 키 매핑 테스트

다음 번에는 데이터베이스 연결 테스트 후, DTO와 DAO를 만들어야 한다.