728x90
์๋ ํด๋์ค ์์ ํ๋๋ฅผ ๋ฃ์ด์ค ๋ new () ...์์ผ๋ก ์ธ์คํด์ค ์์ฑํ์ฌ ๋ฃ์ด์ค๋ค.
ํ์ง๋ง
@RestController
๋ฅผ ๋ถ์ฌ์ค ํด๋์ค๋ ์คํ๋ง์์ ํ๋์ ์ธ์คํด์ค๋ฅผ ๋ณด๊ดํ๊ณ ์๋ค.
๊ทธ๋์ Autowired ์ธ ๋๋ง๋ค ํด๋น ํ๋์ ๋์ ํด์ค๋ค.
@Autowired
private MarketService marketService;
//์ฐธ๊ณ ๋ก
marketService
๋ ์๋น์ค@Service๋ผ๋ ์ด๋ ธํ ์ด์ ๋ถ์ฌ์ค๋ค.
์๋น์ค ๋ถ์ธ ๊ฒ๋ค๋ง ์คํ๋ง ์ปจํ ์คํธ์ ์ธ์คํด์ค๋ค์ด ๋ค์ด๊ฐ๊ฒ ๋๋๋ฐ
์ด๋ฌํ ์ธ์คํด์ค๋ค์ '๋น'์ด๋ผ๊ณ ๋ถ๋ฅธ๋ค.
package com.bbokkie.coinner.controller;
import com.bbokkie.coinner.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MarketController {
@Autowired
private MarketService marketService;
@GetMapping("/price")
public double getPrice(
@RequestParam String market, @RequestParam String coin
){
marketService.getPrice(market,coin);
return 123.456;
}
}
package com.bbokkie.coinner.service;
import org.springframework.stereotype.Service;
@Service
public class MarketService {
public double getPrice(
String market, String coin
){
return 123.444;
}
}
728x90
'Java & Spring > ์คํ๋ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์๋ฐ][์คํ๋ง] GET ์์ฒญ์ param์ ์ค์ ํ๊ธฐ (0) | 2023.01.01 |
---|---|
[์๋ฐ][์คํ๋ง] ํฌํธ๋ฒํธ ๋ฐ๊พธ๊ธฐ (0) | 2023.01.01 |
[์คํ๋ง] ์ธํ ๋ฆฌ์ ์ด, ์ดํด๋ฆฝ์ค ์คํ๋ง์คํํธ ์ํฌํธ (0) | 2022.12.20 |
[์คํ๋ง๋ถํธ] STS ์ค์น : Spring Tool Sulte 4 (0) | 2022.12.18 |
[AWS EC2] ์ธ์คํด์ค์์ ํฐ์บฃ์ด ์ ์ค์น๋์ง ์๋ ๊ฑด (0) | 2022.04.20 |