zoukankan      html  css  js  c++  java
  • 单纯的简单的mybatis有注解

    同一个包下:com.com

    1.IStudentDAO.java

    简单的加入:

    //小心Insert要大写,小写会出错的,有时后面的括号不要少写
         @Insert("insert into student(id,sname,birth,score) values(#{id},#{sname},#{birth},#{score})")
         public void insert(Student student); //插入  

    2.IStudentDAOTest.java

    少量代码:

    String resource = "com/com/mybatis-config.xml";
            Reader reader = Resources.getResourceAsReader(resource);
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(reader);
           
            factory.getConfiguration().addMapper(IStudentDAO.class);//利用注解要加上这句是注册,否则不用加
            SqlSession session = factory.openSession();
            IStudentDAO iStudentDAO = session.getMapper(IStudentDAO.class);

    3.Student.java

    这里面的同无注解的一样

    4.mybatis-config.properties

    这个也同无注解的一样

    5.mybatis-config.xml

    这个里面的代码要把mapper删除掉,因为在DAO中注解过了,不需要调用mapper.xml

    删除的代码是:<!--
     利用Annotation,固把此注释掉不用,而在IStudentDAO中注解了
     <mappers>
      <mapper resource="com/com/StudentMapper.xml" />
     </mappers>
    -->

    6.StudentMapper.xml

    这是配置文件就可以不用了。

  • 相关阅读:
    ubuntu下Nodic开发环境搭建
    usb_modeswitch移植
    STM32F4编程手册学习2_内存模型
    STM32F4 编程手册学习1_编程模型
    ARM架构中的程序执行与调用
    锲形文字 数字
    疑问
    lisp 题目
    面试官在面试时让我去破解一个软件,我成功了
    php CI ip限制
  • 原文地址:https://www.cnblogs.com/yyy88168/p/3201247.html
Copyright © 2011-2022 走看看