首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

SSM框架之MyBatis3专题3:关联

1.1.3 定义Dao层接口 public interface ICountryDao { Country selectCountryById(int cid); } 1.1.4 定义测试类 public class Mytest { private SqlSession session; private ICountryDao dao; @Before public void setUp() { session = MyBatisUtils.getSqlSession(); dao = session.getMapper(ICountryDao.class); } @After public void tearDown() { if(session != null) { session.close(); } } @Test public void test01() { Country country = dao.selectCountryById(1); System.out.println(country); } } 1.1.5 定义映射文件 1、多表连接查询方式 <mapper namespace="com.eason.mybatis.dao.ICountryDao"> <resultMap type="Country" id="countryMapper"> <id column="cid" property="cid"/> <result column="cname" property="cname"/> <collection property="ministers" ofType="Minister"> <id column="mid" property="mid"/> <result column="mname" property="mname"/> </collection> </resultMap> <select id="selectCountryById" resultMap="countryMapper"> select cid, cname, mid, mname from t_country, t_minister where cid=#{xxx} and cid=countryId </select> </mapper>

01
领券