mybatis一对多查询 Cause: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3

报错信息:The error occurred while handling results

### Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
### The error may exist in file [C:\major\IntelliJ IDEA 2019.1.3\workspace\springboot\HotelManagement\target\classes\com\wordpython\admin\dao\mapper\RoomMapper.xml]
### The error may involve com.wordpython.admin.dao.RoomMapper.selectPhoto
### The error occurred while handling results
### SQL: SELECT room_number,img_url,photo_name from photo JOIN room USING(room_number)   where room_number=? and room.hotel_id=? and photo.hotel_id=?;
### Cause: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3]

信息中明显提示:The error occurred while handling results(处理结果时发生错误)

场景:

        mybaits实现的一对多查询:

      mapper.xml :

    
    
    
        
        
        
        
            
        
    
    

    实体类:  photo.java

@Data
public class Photo {
    private String photo_id;
    private String room_number;//房间编号
    private String hotel_id;//酒店id
    private String img_url;//图片文件夹名字
    private String photo_name;//图片名字
    private List photo_names;//房间图片名字集

    //mapper.xml查询成功后,会调用该实体类的构造方法而返回一个有值的对象
//    public Photo(String photo_id, String img_url, String photo_name) {
//        this.photo_id = photo_id;
//        this.img_url = img_url;
//        this.photo_name = photo_name;
//    }
     //mapper.xml查询成功后,会调用该实体类的构造方法而返回一个有值的对象
    public Photo(){

    }

以上配置是正确的,报错的原因是实体类photo中没有相应的构造方法。

必须包含不带参数的构造方法 或  和查询语句返回的字段数相应的参数的构造方法。

你可能感兴趣的:(mybatis,javaweb,springboot)