Student.xml the properties of this set parameter
<id= "Insertstudent" parameterclass= "Student"> INSERT INTO Student (name, age) VALUES (#name #, #age #) </insert>
Studentimpl.java using the Add method to invoke the added statement of the mapped file being developed
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 Continue Testing
PackageCn.test.main;Importjava.util.List;Importcn.test.domain.Student;Importcn.test.service.IStudent;ImportCn.test.service.StudentImpl; Public classTest {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubStudent student3=NewStudent (); Student3.setage (20); Student3.setname (Demacia); Istudent Istudent3=NewStudentimpl (); Istudent3.addstudent (STUDENT3); } }
Insert an entity into the IBatis