분류 전체보기

    The 2020 Web Developer Roadmap (개발자 로드맵)

    출처 levelup.gitconnected.com

    02. share project on GitHub

    git 저장소를 추가한다. .gitignore 화일을 추가한다. /.idea /node_module /dist package-lock.json version control 탭에서 working area 에 있는 화일은 staging area로 add하고 commit 한다. commit 후 VCS > import into version control > share project on github로 프로젝트를 github에 공유한다.

    01. express 설정

    hero-server 라는 이름의 폴더를 만든다. 폴더를 만든후 IDEA 에서 File > Oen 메뉴에서 해당 폴더를 연다. 하단의 Terminal 메뉴에서 npm 저장소를 만든다. package.json 화일이 생성되었음을 확인하자. 해당 화일을 열어서 확인하자. 이제 node 로 REST 서버를 구성하기 위해 필수 라이브러리인 express 모듈을 설치한다. package.json에 의존성 모듈이 설치된것고 node_module에 해당 모듈이 설치됨을 확인하자. src/index.js 화일을 만들고 아래와 같이 입력한다. var express = require('express'); var app = express(); app.get('/api/hello', function(req, res) { re..

    12. file upload

    프로토콜 파일을 업로드하는 메서드는 Post 이다. 그런데 Content-Type이 좀 독특하다. Request할때 헤더를 fiddler를 사용해서 살펴보면, Content-Type: multipart/form-data; boundary=abcdefghhhhhhhhhhhh body에 보내는 데이터의 content type이 form-data이긴 한데 여러부분으로 나누어 보낸다는 multipart 형태이다. 그리고 각각의 part 사이는 boundary를 이용해서 구분하는데, 앞에 –를 붙인다. 그리고 맨 마지막에 끝날때는 다시 –를 붙인다. 예를 들어 3 part를 전송한다고 가정하면 아래와 같다. –abcdefghhhhhhhhhhhh one part … –abcdefghhhhhhhhhhhh two pa..

    11. hero delete method

    PERSISTENCE @Delete({""}) int deleteHero(int hero_id); CONTROLLER @DeleteMapping("hero") public ResultVO removeHero(@RequestParam int hero_id) { int result = heroMapper.deleteHero(hero_id); if ( result > 0) { return new ResultVO(0, "success"); } else { return new ResultVO(100, "fail"); } } 호출 유알엘은 /api/hero 이고 메서드는 delete, 입력파라메터는 Query Parameter로 받는다. delete메서드는 Get 메서드와 동일하게 Request의 body가 존재하..

    10. hero put method

    PERSISTENCE @Update({""}) int updateHero(HeroVO hero); update 되는 property가 있을수도 있고 없을수도 있기 때문에 if 구문으로 null여부를 체크한다. 그리고, update 구문을 만들때 set key1 = value1, key2 = value2, 이런식으로 만들면 맨 뒤에 콤마는 없어야 한다. 그러므로 trim 구문을 사용하여 prefix 는 set으로 맨 앞에 set을 위치 시키고 맨뒤에 콤마는 없애라는 suffixOverrids=”,” 구문을 맨 뒤에 넣는다. CONTROLLER @PutMapping("/hero") public ResultVO modifyHero(@RequestBody HeroVO hero) { int result = her..

    09. hero get method

    PERSISTENCE 구현 hero_id를 입력으로 해서 하나의 hero를 가져오는 api와 모든 hero를 가져오는 두개의 get method가 필요하다. @Select({""}) List findHero(); @Select({""}) HeroVO findOneHero(int hero_id); CONTROLLER 구현 @GetMapping("/hero/{hero_id}") public HeroVO findOneHero(@PathVariable int hero_id) { return heroMapper.findOneHero(hero_id); } @GetMapping("/heroes") public List findOneHero() { return heroMapper.findHero(); } POSTMAN..