by-nc-sa     개발자, DBA가 함께 만들어가는 구루비 지식창고!

4. Annotation을 이용한 Hello World 예제




4. Annotation을 이용한 Hello World 예제

4.1 Controller 서블릿 작성

AnnotationHelloWorldController.java
package net.gurubee.web.sample.annotation;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/sample/ahello.do")
public class AnnotationHelloWorldController {

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView helloWorld() {

        ModelAndView mv = new ModelAndView();
        mv.setViewName("sample/hello");
        mv.addObject("msg", "annotation hello world");

        return mv;
    }

}

4.2 mvc-dispatcher-servlet.xml 설정

  • component-scan 설정
mvc-dispatcher-servlet.xml
   <context:component-scan base-package="net.gurubee.web.sample.annotation" />

4.3 jsp 사용

  • /WEB-INF/pages/sample/hello.jsp 파일을 사용.

4.4 테스트

문서정보

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.