1. 注解开发
a) @Select , @Update ,@Delete,@Insert, @Param
@Select("select * from t_student order by id") public List<Student> selectAll();
// 在使用@Param注解时:@Param("值") 必须与条件 where id = #{值} 相等 @Select("select * from t_student where id = #{id}") public Student selectById(@Param("id") int sid);
@Update("update t_student set name = #{name} where id = #{id}") public int updateStudent(Student stu);
@Delete("delete from t_student where id = #{id}") public int deleteSudent(@Param("id") int id);
@Insert("insert into t_student (name,gender,age) values(#{name},#{gender},#{age})") public int insertStudent(Student stu); |
b) @Results , @Result
Id=true:跟<id property="id" column="id"/>意思一样。 @Results(value={ @Result (id=true, column="id",property="cid"), @Result (column="name",property="cname"), @Result (column="beginTime",property="beginTime"), }) @Select("select id,name,beginTime from t_classes") public List<Classes> findAll(); |
c) @Many
@Select("select * from t_student where cid=#{0}") List<Student> findStuById(int cid); @Results(value={ @Result(id=true,property = "cid",column="id"), @Result(property = "cname",column="name"), @Result(property = "beginTime",column="beginTime"), @Result(property = "students",many=@Many(select="findStuById"),column="id"), }) @Select("select * from t_classes") List<Classes> findAll(); |