zoukankan      html  css  js  c++  java
  • Mybaits-从零开始-Hello World(暂不考虑命名规范化)

    1、mybatis-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>  
    <!DOCTYPE configuration  
      PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
      "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
        <!-- 对事务的管理和连接池的配置 -->
        <environments default="development">
            <environment id="development">
                <transactionManager type="JDBC" />
                <dataSource type="POOLED">
                    <property name="driver" value="oracle.jdbc.driver.OracleDriver" />
                    <property name="url"
                        value="jdbc:oracle:thin:@192.168.0.131:1521:portal" />
                    <property name="username" value="mybatis" />
                    <property name="password" value="mybatis" />
                </dataSource>
            </environment>
        </environments>
    
    
        <!-- mapping 文件路径配置 -->
        <mappers>
            <mapper resource="com/myOrg/deptUseMapper.xml" />
        </mappers>
    </configuration>

    2、deptUseMapper.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.myOrg.deptUseMapper">
        <select id="getDeptUserByID"  resultType="com.myOrg.DeptUserDomain">
            select * from deptUser where id='46df5041-5fe2-4bce-aaa1-9031ab929df4'
        </select>
        <insert id="save" parameterType="com.myOrg.DeptUserDomain">
            insert into deptUser value(1,2,3)
        </insert>
    </mapper>

    3、DeptUserDomain.java

    package com.myOrg;
    
    import java.sql.Date;
    
    public class DeptUserDomain {
        String name;
        Date hireDate;
        float salary;
        String id;
        
        public void setId(String id) {
            this.id = id;
        }
        public String getId() {
            return id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Date getHireDate() {
            return hireDate;
        }
        public void setHireDate(Date hireDate) {
            this.hireDate = hireDate;
        }
        public float getSalary() {
            return salary;
        }
        public void setSalary(float salary) {
            this.salary = salary;
        }
        
        
    }

    4、DeptUserOpt.java

    package com.myOrg;
    
    import org.apache.ibatis.session.SqlSession;
    
    public class DeptUserOpt {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            SqlSession session=DeptUserUtil.getSession();
            DeptUserDomain domain=session.selectOne("com.myOrg.deptUseMapper.getDeptUserByID");
            System.out.println(domain.getName());
            session.commit();
            session.close();
        }
    
    }

    5、DeptUserUtil.java

    package com.myOrg;
    
    import org.apache.ibatis.session.SqlSession;
    
    public class DeptUserOpt {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            SqlSession session=DeptUserUtil.getSession();
            DeptUserDomain domain=session.selectOne("com.myOrg.deptUseMapper.getDeptUserByID");
            System.out.println(domain.getName());
            session.commit();
            session.close();
        }
    
    }

    6、目录

    7、数据表

    8、运行结果

  • 相关阅读:
    归类常用控件GroupBox、TabControl、Expander
    ScrollViewer控件
    捕获鼠标位置
    5、标记拓展
    如何实现文件增量同步——算法
    常用的 Nand Flash 指令如下:
    Consistent Hashing算法
    循环冗余检验 (CRC) 算法原理
    yaffs2根文件系统的构建过程
    linux内存管理之uboot第一步
  • 原文地址:https://www.cnblogs.com/jiangtao1218/p/8598413.html
Copyright © 2011-2022 走看看