Student.xml 这个制定参数的属性
<insert id="insertStudent" parameterClass="Student" > INSERT INTO Student (name, age) VALUES (#name#, #age#) </insert>
StudentImpl.java 使用添加方法,调用制定的映射文件的添加语句
public void addStudent(Student student) { // TODO Auto-generated method stub try { sqlMapClient.insert("insertStudent",student); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Test.java 继续测试
package cn.test.main; import java.util.List; import cn.test.domain.Student; import cn.test.service.IStudent; import cn.test.service.StudentImpl; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Student student3= new Student(); student3.setAge(20); student3.setName("德玛西亚"); IStudent istudent3 = new StudentImpl(); istudent3.addStudent(student3); } }