■ Spring Controller 예제
@Controller public class TextSampleController { @RequestMapping( value = "textsample/text.do", method = RequestMethod.GET, produces=MediaType.TEXT_PLAIN_VALUE) @ResponseBody public String text(@ModelAttribute Params params) throws Exception { return "Hello, "+params.getName(); } }
■ angularjs $http client 예제
<!DOCTYPE html> <html ng-app="myApp"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8"> <head> <title></title> <script src="/js/angularjs/1.5.6/angular.js"></script> <script src='/js/jquery/jquery-1.11.0.min.js'></script> <script> var myApp = angular.module("myApp",[]); myApp.controller("myAppCtrl", function($scope,$http){ $scope.result = ""; $http({ method : 'GET', url : '/textsample/text.do', params : { name:'미리내' } }) .success(function(response){ $scope.result = response; }); }); </script> </head> <body ng-controller="myAppCtrl"> <h1>AngularJS Built-in Service $http<br/></h1> <hr/> <div>{{result}}</div> </body> </html>
■ 브라우저 결과
■ 클라이언트에서 POST로 요청했으면 Spring Controller에서도 POST로 받아야 하고, GET으로 요청을 했으면 GET으로 받아야 한다.
그렇지 않으면 405 (Method Not Allowed) 에러가 발생한다. 만약 GET, POST방식을 동시에 지원하고자 한다면 아래와 같이 method부분에 GET, POST를 같이 적어준다.
@RequestMapping( value = "textsample/text.do", method = {RequestMethod.POST,RequestMethod.GET}, produces=MediaType.TEXT_PLAIN_VALUE) @ResponseBody public String text( @ModelAttribute Params params) throws Exception { return "Hello, "+params.getName(); }
- SpringBoot Port 변경 2022년 12월 27일
- Spring 트랜잭션 관리 2019년 6월 20일
- Spring RESTful 웹 서비스 사용하기 2019년 6월 19일
- Spring RESTful 웹 서비스 2019년 6월 19일
- Spring Scheduling Task 예제 2019년 6월 18일
- AngularJS angular.copy 사용법, angular 복사 2019년 5월 17일
- AngularJS fromJson, toJson 사용법 2019년 5월 15일
- AngularJS에서 ng-style사용시 조건문 이용방법 2019년 4월 25일
- AngularJS에서 ng-style사용시 함수 이용방법 2019년 4월 23일
- AngularJS 동적 HTML, Function 추가 2019년 4월 15일
- AngularJS에서 팝업창 띄우기 2019년 4월 2일
- spring mybatis mysql 연결 예제 2018년 5월 4일
- AngularJS 하나의 모듈에 factory 다중 등록 2018년 2월 26일
- AngularJS factory 예제 2018년 2월 26일
- AngularJS forEach ng-repeat 예제 2018년 2월 19일
- Spring Path Parameter 예제 2018년 2월 13일
- AngularJS $http, spring TEXT response 예제 2018년 1월 17일
- AngularJS selectbox 간단한 예제 2018년 1월 15일
- AnuglarJS forEach 예제 2018년 1월 12일
- AngularJS checkbox 제어 및 활성/비활성(ng-disabled) 예제 2018년 1월 8일
- AngularJS button 활성/비활성(ng-disabled) 예제 2018년 1월 8일
- AngularJS radio 활성/비활성(ng-disabled) 예제 2018년 1월 8일
- AngularJS $broadcast, $emit, $on 예제 2018년 1월 3일
- AngularJS – $watch $digest $apply Life Cycle 2017년 12월 26일
- AngularJS $watchCollection 2017년 12월 26일
- AngularJS $watchGroup 2017년 12월 26일
- AngularJS $watch 2017년 12월 26일
- jdom2를 이용한 spring xml response(응답) 2017년 12월 5일
- jquery xml 요청, spring xml 리턴 2017년 12월 5일
- spring controller에서 get, post 동시 허용 방법 2017년 12월 5일
- mybatis, oracle procedure(오라클 커서)를 통한 데이터 조회 2017년 11월 6일
- HTTP 406 Not Acceptable in Spring, Jackson, Json 2017년 11월 6일
- AngularJS 반복문 ng-repeat 2017년 7월 22일
- AngularJS $timeout 2017년 7월 22일
- AngularJS Show/Hide, 보이기/숨기기 2017년 7월 16일
- AngularJS 라디오 버튼 제어 2017년 7월 16일
- AngularJS시작하기, Hello AngularJS 2017년 7월 15일
- ServletContextLister를 구현한 웹 애플리케이션 시작 시 작업 2016년 5월 2일
- Web Application MessageResource 2016년 3월 8일
- org.mariadb.jdbc.internal.common.QueryException : No database selected 2016년 2월 19일
- jquery spring – checkbox로 선택된 배열 주고 받기 2015년 8월 15일
- jquery spring ajax call 2015년 8월 15일
- spring json return 2015년 8월 15일
- spring exception – SimpleMappingExceptionResolver 2015년 8월 8일