mybatis官方文档提供注解
@TableName(“table_name”)
就可以把我们的类对应起来
还用很多其他注解可以用来除了不一致
@Results代替< resultMap >标签,加入多个@Result注解
@Result 代替< id >< Result >
可以使用
column-数据表字段
property-类对应的属性名
one-和!@One配合注解,一对一映射
many和@Many配合,一对多
@One代替< assocation>
使用格式
@Result(column=“” , property=“”,one=@One(select = “”))
@Many代替< collection>
使用格式
@Result(column=“” , property=“”,many=@Many(select = “”))
@Select("select * from t_user")
@Results(
{
@Result(column = "id",property = "id"),
@Result(column ="username",property = "username"),
@Result(column = "password",property = "password"),
@Result(column = "birthday",property ="orders",javaType = List.class,
many=@Many(select="com.example.mpdemo.apper.OrderMapper.selectByUid")
)
}
)
List<User> selectAllUserAndOrders();
不过有些地方bug跑不通了