@Service @Autowired 어노테이션, ModelAndView_sts
2022. 2. 20. 15:15ㆍksmart_Framework/spring
728x90
@Service
해당 클래스를 루트 컨테이너에 Bean 객체로 생성해주는 어노테이션
패키지 | ksmart.hellospringboot.service |
클래스 | KsmartService |
package ksmart.hellospringboot.service;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
@Service
public class KsmartService {
@GetMapping("/ksmartView")
public String ksmart(String level) {
String result="";
if(level !=null && level.equals("관리자")) {
result="한국스마트정보교육원42기 김문영";
}else {
result="관리자아님";
}
return result;
}
}
package ksmart.hellospringboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import ksmart.hellospringboot.service.KsmartService;
@Controller
public class KsmartController {
@GetMapping("/ksmartView")
public String ksmartView(Model model) {
KsmartService service=new KsmartService();
String result = service.ksmart("관리자");
model.addAttribute("view",result);
return "/view";
}
}
package ksmart.hellospringboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import ksmart.hellospringboot.service.KsmartService;
@Controller
public class KsmartController {
@GetMapping("/ksmartView")
public String ksmartView(Model model) {
KsmartService service=new KsmartService();
String result = service.ksmart("관리자아님");
model.addAttribute("view",result);
return "/view";
}
}
@Autowired
↓
ModelAndView
↓
728x90
'ksmart_Framework > spring' 카테고리의 다른 글
mybatis_sts (0) | 2022.02.22 |
---|---|
springboot 백업_sts (0) | 2022.02.20 |
thymeleaf 와 Model 객체 사용법_sts (0) | 2022.02.17 |
기본문법_sts (0) | 2022.02.17 |
Hello Spring Boot!_sts (0) | 2022.02.17 |