mybatis之接口开发

一:规则:

        1)接口名称必须和mapper文件名称相同

        2)接口包路径和命名空间一致(接口文件和mapper文件在一起)

                  3)接口中要声明的方法名和某个sql配置中的id属性一致

        4)参数和返回值,要按java规则来写

例:

   


以id属性id为例


PersonMapper接口类中:

                 

/**
 * Created by **** on 2017/3/24.
 */
public interface PersonMapper {
    public List<Person> find(Map map);
}

测试类:TestPersonInterface

     

/**
 * Created by 王新起 on 2017/3/24.
 */
public class TestPersonInterface {
    private SqlSessionFactory factory;
    @Before //最先运行  获得faction工厂
    public void init() throws IOException {

        String resource="sqlMapConfig.xml";
        InputStream is = Resources.getResourceAsStream(resource);
        factory= new SqlSessionFactoryBuilder().build(is);
    }

    @Test //接口开发
    public void testFind(){
        SqlSession session=factory.openSession();

        //获取接口对象
        PersonMapper pm=session.getMapper(PersonMapper.class);
        Map map =new HashMap();
        map.put("name","aa");
        List<Person> list=pm.find(map);
        System.out.println(list.size());
        for (Person p :list){
            System.out.println(p);
        }
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值