zoukankan      html  css  js  c++  java
  • 01_4_插入一个实体对象

    01_4_插入一个实体对象

    1. 配置映射配置

    <insert id="insertStudent" parameterClass="Student">

      insert into Student(sid, name, major, birth, score) values(#sid#, #name#, #major#, #birth#, #score#)

      </insert>

    2. 实现方法类

    public void addStudent(Student student) {

    try {

    sqlMapClient.insert("insertStudent", student);

    } catch (SQLException e) {

    e.printStackTrace();

    }

    }

    3. 调试及其结果

    public static void main(String[] args) {

    IStudentDAO dao = new IStudentDAOImpl();

    Student student = new Student();

    student.setSid(6);

    student.setName("fengge");

    student.setScore(100);

    dao.addStudent(student);

    for(Student stu : dao.queryAllStudent()) {

    System.out.println(stu);

    }

    }

    [sid:6, name:fengge, major:null, birth:null, score:100.0]

    [sid:1, name:李明, major:语文, birth:Tue Mar 27 00:00:00 CST 2018, score:100.0]

    [sid:2, name:可可, major:英语, birth:Mon Mar 12 00:00:00 CST 2018, score:120.0]

    [sid:3, name:天天, major:数学, birth:Thu Mar 22 00:00:00 CST 2018, score:80.0]

  • 相关阅读:
    java语言基础
    常用4种限流算法介绍及比较
    如何用Redis实现分布式锁
    翻转字符串
    JAVA之io流
    JAVA之Collections集合
    【转】IT行业岗位以及发展方向
    JAVA之字符串
    JAVA之数组
    Linux之判断字符串是否为空
  • 原文地址:https://www.cnblogs.com/flyback/p/8660507.html
Copyright © 2011-2022 走看看