Spring Controller return 유형
html에서
<a href="hello()">를 써준다 ?? a 태그 안의 href 속성에 이동할 페이지를 써주어야 한다
만약 javascript 안의 함수를 호출하고 싶다면 javascript를 명시해주어야 한다
=> <a href="javascript:hello()">
※언제 쓸까? Javascript 안에서 ajax를 할 때 쓴다
@RequestMapping("hello")
public String doMsg() {
return "Hello, Spring~!!"; //요청 브라우저에게 '안녕' 메시지를 전달하고 싶다!!
}
⇒ @ResponseBody를 붙여준다
@RequestMapping("hello")
public @ResponseBody String doMsg() {
return "Hello, Spring~!!"; //요청 브라우저에게 '안녕' 메시지를 전달하고 싶다!!
}
--------------------------------------------------------------------@RequestMapping("hello")
public @ResponseBody String doMsg() {
return "안녕, 스프링프레임워크~!!"; //요청 브라우저에게 '안녕' 메시지를 전달하고 싶다!!
}
※ @ResponseBody, @RestController 한글처리
===> servlet-context.xml의 <annotation-driven>안에 <message-converters>추가
<annotation-driven>
<!-- @ResponseBody 한글처리 -->
<message-converters>
<beans:bean class="org.springframework.http.converter.StringHttpMessageConverter">
<beans:property name="supportedMediaTypes">
<beans:value>text/html;charset=UTF-8</beans:value>
</beans:property>
</beans:bean>
</message-converters>
</annotation-driven>
'Spring' 카테고리의 다른 글
"Spring+MyBatis 프로젝트 만들 수 있을까?" (0) | 2018.08.29 |
---|---|
"WAS 없이 실행이 될까?" (0) | 2018.08.28 |
"Spring ajax는 알아서 해준다?" (0) | 2018.08.28 |
"Spring Controller 전격 파헤치기" (0) | 2018.08.28 |
"Spring DB Test 한 번에 끝내기" (0) | 2018.08.28 |