package com.sf.mapper;


import com.sf.entity.Student;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title StudentMapper
 * @description
 * @create 2025/11/9
 */
public interface StudentMapper {
    /**
     * 根据班级id查询学生
     * @param cid
     * @return
     */
    @Select("SELECT * FROM student WHERE cid=#{cid}")
    @Results({  //只查询我们需要的内容
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age")
    })
    List<Student> selectByClassId(int cid);

    /**
     * 查询所有课程
     * @return
     */
    @Select("SELECT DISTINCT s.id,s.name,s.age " +
            "FROM student s,stu_cr sc " +
            "WHERE s.id=sc.sid ")
    @Results({
            @Result(column = "id",property ="id" ),
            @Result(column = "name",property ="name" ),
            @Result(column = "age",property ="age" ),
            @Result(
                    column = "id", //被包含对象的字段名
                    property ="courses",//被包含对象的对象名
                    javaType = List.class,//实际数据类型
                    many = @Many(select = "com.sf.mapper.CourseMapper.selectByStudentId")
            )

    })
    List<Student> selectAll();
}
