ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 240206_스프링부트 쇼핑몰 프로젝트
    카테고리 없음 2024. 2. 6. 16:56

    클래스분석 UML Class Diagram

    인텔리제이->패키지 선택->우클릭->diagrams->class선택->diagrams

    itemRepository.java
    
        @Modifying
        @Query("DELETE FROM CartItem c WHERE c.item.id = :itemId")
        void deleteCartItemByItemId(Long itemId);
    
        @Modifying
        @Query("DELETE FROM OrderItem o WHERE o.item.id = :itemId")
        void deleteOrderItemByItemId(Long itemId);
    
        @Modifying
        @Query("DELETE FROM ItemImg o WHERE o.item.id = :itemId")
        void deleteItemImgByItemId(Long itemId);
    ------------------------------------------------------------------------------------------
    ItemService.java
    
        @Transactional
        public void deleteItem(Long itemId) {
            
            // CartItem, OrderItem, ItemImg 엔티티들을 삭제
            itemRepository.deleteItemImgByItemId(itemId);
            itemRepository.deleteCartItemByItemId(itemId);
            itemRepository.deleteOrderItemByItemId(itemId);
    
            // 아이템 삭제
            itemRepository.deleteById(itemId);
        }
    ------------------------------------------------------------------------------------------
    itemController.java
    
        @DeleteMapping(value = "/item/{itemId}")    // 아이템 삭제 수정
        public @ResponseBody ResponseEntity deleteItem(@PathVariable("itemId") Long itemId){
    
            itemService.deleteItem(itemId);
    
            return new ResponseEntity<Long>(itemId, HttpStatus.OK);
        }
    
    ------------------------------------------------------------------------------------------
    itemMng.html
              function deleteItem(obj){
                var itemId = obj.getAttribute('data-id');
                var token = $("meta[name='_csrf']").attr("content");
                var header = $("meta[name='_csrf_header']").attr("content");
    
                var url = "/item/" + itemId;
    
                $.ajax({
                    url      : url,
                    type     : "DELETE",
                    beforeSend : function(xhr){
                        xhr.setRequestHeader(header, token);
                    },
                    dataType : "json",
                    cache   : false,
                    success  : function(result, status){
                        location.href='/admin/items';
                    },
                    error : function(jqXHR, status, error){
                        if(jqXHR.status == '401'){
                            alert('로그인 후 이용해주세요');
                            location.href='/members/login';
                        } else{
                            alert(jqXHR.responseJSON.message);
                        }
                    }
                });
            }
    
    
    	    <td>
                        <button type="button" class="close" aria-label="Close">
                            <span aria-hidden="true" th:data-id="${item.id}" 
                            onclick="deleteItem(this)">x</span>
                        </button>
                    </td>
    ------------------------------------------------------------------------------------------


    실습-수정내용v1.1-shop_master.pptx
    2.22MB

     

Designed by Tistory.