2016년 12월 19일 월요일

[자바교육,스프링교육,JPA교육학원_탑크리에듀]#7. 스프링부트,JPA게시판(글읽기)-오라클,AngularJS,컨트롤러쪽에 함수 하나만 추가하면 된다.

#7. 스프링부트,JPA게시판(글읽기)-오라클,AngularJS,컨트롤러쪽에 함수 하나만 추가하면 된다.

게시판 글읽기

n  간단히 AngularJS 컨트롤러쪽에 함수 하나만 추가하면 된다.

[src/main/webapp/js/board_controller.java]
'use strict';

App.controller('BoardController', ['$scope', 'BoardService',
      function($scope, BoardService) {
          var self = this;
          self.board={id:null, name:'',passwd:'',title:'',content:''};
          self.page=[];
              
          //리스트 보기
          self.list = function(curPage){
              BoardService.list(curPage)
              .then(
                 function(data) {
                     self.page = data;
                     console.log("[controller:list]", self.page);
                     //alert("목록보기 성공!");
                 },
                 function(errResponse){
                     console.error('Error while fetching page...');
                 }
              );
          };  
         
          //글 입력
          self.create = function(board) {
              BoardService.create(board)
              .then(
                  function() {
                    alert("Save OK!");
                    self.list(0);
                  },
                  function(errResponse){
                     console.error('Error while creating Article.');
                  }
               );   
           };

          self.list(0);
         
          // ADD or UPDATE 버튼 클릭
          self.submit = function() {
              if(self.board.id===null){                     
                  self.create(self.board);         
                  console.log("[controller:create]", self.board);
              }else{
                  //self.update(self.board, self.board.id);
                  console.log('Article updated with id ', self.board.id);
              }
              self.reset();             
          };  
         
          //글읽기
          self.edit = function(id){
              console.log('[controller:edit]', id);
              console.log("3333", self.page);
              for(var i = 0; i < self.page.content.length; i++){
                  if(self.page.content[i].id === id) {
                     self.board = angular.copy(self.page.content[i]);
                     console.log("[read article]", self.board);
                     break;
                  }
              }
          }; 
         
          self.reset = function(){
          self.board={id:null, name:'',passwd:'',title:'',content:''};
              $scope.myForm.$setPristine(); //reset Form
          };
         
}]);

read.png

댓글 없음:

댓글 쓰기