IT/Spring

MyBatisSystemException

iamhyeon 2024. 11. 25. 01:59

org.mybatis.spring.MyBatisSystemException
 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:97)

 

Caused by: org.apache.ibatis.reflection.ReflectionExceptionCould not set property 'filepath' of 'class kr.co.sonystore.models.Cart' with value '/products/camera1/clr1_0.png' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'filepath' in 'class kr.co.sonystore.models.Cart'

 

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'filepath' in 'class kr.co.sonystore.models.Cart'
 at org.apache.ibatis.reflection.Reflector.getSetInvoker(Reflector.java:377)
 at org.apache.ibatis.reflection.MetaClass.getSetInvoker(MetaClass.java:164)
 at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:169)
 ... 34 more

 

MyBatis 가 filepath 속성을 Cart 클래스에 설정하려고 할 때 문제가 발생한 것

 

Cart 클래스에 filepath 속성에 대한 setter 메서드가 없다는 ReflectionException 발생

 

MyBatis 는 SQL 쿼리 결과를 Java 객체에 맵핑할 때, 해당 속성에 대한 setter 메서드를 사용한다

Cart 클래스에 filepath 속성에 대한 setter 메서드가 없으면 맵핑에 실패한다

 

⬇️ Cart.java

package kr.co.sonystore.models;

import lombok.Data;

@Data
public class Cart {
    private int cartid;    // 일련번호          
    private int count;     // 수량               
    private int memberid;  // 회원의 일련번호 
    private int prodid;    // 상품의 일련번호   
    private String color;  // 상품의 색상  
}

 

⬇️ CartMapper.java

/**
 * 장바구니 목록을 조회한다
 * @param input - 조회할 장바구니 정보에 대한 모델 객체
 * @return 조회된 장바구니 목록
 */
@Select (
    "<script> \n" + 
    "SELECT cartid, memberid, c.prodid, filepath, title,\n" +
    "c.color, price, count, price*count AS sum \n" +
    "FROM carts c \n" +
    "INNER JOIN products p ON c.prodid = p.prodid \n" +
    "INNER JOIN images i ON c.prodid = i.prodid \n" + 
    "<if test = 'color != null'> INNER JOIN colors clr ON c.color = clr.color </if> \n" + 
    "WHERE memberid = 2 AND i.thumbnail='Y' \n" +
    "ORDER BY cartid \n" +
    "</script>"
)        
@Results ( id="cartMap", value = {
    @Result ( property="cartid", column="cartid" ),
    @Result ( property="memberid", column="memberid" ),
    @Result ( property="prodid", column="prodid" ),
    @Result ( property="filepath", column="filepath" ),
    @Result ( property="title", column="title" ),
    @Result ( property="color", column="color" ),
    @Result ( property="price", column="price" ),
    @Result ( property="count", column="count" ),
    @Result ( property="thumbnail", column="thumbnail" )
} )
public List<Cart> selectList(Cart input);

 

 

 

 

 

 

 

 

반응형

'IT > Spring' 카테고리의 다른 글

Error  (0) 2024.11.26
Thymeleaf  (0) 2024.11.26
Spring 파일 업로드 경로 맵핑  (0) 2024.11.21
File Upload  (3) 2024.11.21
Interceptor  (0) 2024.10.23