日期:2014-05-20 浏览次数:21162 次
<resultMap id="studentResultMap" type="student"> <id property="id" column="F_ID" /> <result property="name" column="F_NAME" /> </resultMap> <parameterMap id="studentParameterMap" type="student"> <parameter property="id" resultMap="F_ID"/> <parameter property="name" resultMap="F_NAME"/> </parameterMap> <select id="selectAllStudent" resultMap="studentResultMap"> <![CDATA[ select * from A_TEMP_STUDENT ]]> </select> <insert id="insertStudent" parameterMap="studentParameterMap"> <![CDATA[ insert into A_TEMP_STUDENT (f_id, f_name) values (#{id}, #{name}) ]]> </insert>
/* (non-Javadoc) * @see com.lmiky.database.BaseDAO#list() */ @SuppressWarnings("unchecked") public List<T> list() { SqlSession session = openSession(getSqlMapper()); List<T> students = session.selectList("com.lmiky.student.selectAllStudent"); closeSession(session); return students; } /* (non-Javadoc) * @see com.lmiky.database.BaseDAO#add(com.lmiky.database.pojo.BasePojo) */ public T add(T t) { SqlSession session = openSession(getSqlMapper()); session.insert("insertStudent", t); closeSession(session); return t; } public static void main(String[] args) { StudentDAO<Student> studentDAO = new StudentDAOImpl<Student>(); //添加 Student student = new Student(); student.setId(101l); student.setName("test101"); studentDAO.add(student); //查询 List<Student> students = new StudentDAOImpl<Student>().list(); for(Student s : students) { System.out.println(s); } }