首页 > 其他 > 详细

注解开发中一对多的运用和使用注意项

时间:2019-11-17 21:43:18      阅读:97      评论:0      收藏:0      [点我收藏+]
package com.hope.dao;

import com.hope.domain.User;
import com.sun.xml.internal.bind.v2.model.core.ID;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
* @author newcityman
* @date 2019/11/15 - 22:59
*/
public interface IUserDao {
/**
* 查询所有用户的信息
* @return
*/
@Select(value = "select * from user")
@Results(id = "userMap",value = {
@Result(id = true,column ="id" ,property ="userId" ),
@Result(column = "username" ,property = "userName"),
@Result(column = "sex",property = "userSex"),
@Result(column = "address",property = "userAddress"),
@Result(column = "birthday",property = "userBirthday"),
@Result(column = "id",property = "accounts",
many =@Many(select = "com.hope.dao.IAccountDao.findAccountById"
,fetchType = FetchType.LAZY)),
})
public List<User> findAll();

/**
* 根据用户的id,查询用户
* @param id
* @return
*/
@Select("select * from user where id=#{id}")
@ResultMap(value ={"userMap"} )
User findOne(Integer id);

/**
* 根据用户名模糊查询
* @param username
* @return
*/
@Select("select * from user where username like #{username}")
@ResultMap("userMap")
List<User> findByName(String username);


}

注解开发中一对多的运用和使用注意项

原文:https://www.cnblogs.com/newcityboy/p/11878333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!