<![CDATA[
SELECT student_no studentNo, student_name studentName from t_student
]]>
</select>
<update id="addStudent" parameterType="java.util.Map">
insert into t_student(student_no, student_name)values(seq_student_no.nextval,#{stdName})
</update>
<update id="delStudent" parameterType="java.util.Map">
delete from t_student where student_no=#{stdNo}
</update>
</mapper>
它指向了StudentDAO这个接口
StudentDAO.java
package org.sky.ssi.dao;
import org.sky.ssi.dbo.StudentDBO;
import org.sky.ssi.student.form.*;
import java.util.*;
public interface StudentDAO {
public List<StudentDBO> getAllStudent() throws Exception;
public void addStudent(Map<String, Object> paraMap) throws Exception;
public void delStudent(Map<String, Object> paraMap) throws Exception;
}
StudentDAOImpl.java
package org.sky.ssi.dao.impl;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;
import org.sky.ssi.dao.StudentDAO;
import org.sky.ssi.ibatis.IBatisDAOSupport;
import org.sky.ssi.dbo.StudentDBO;
import org.springframework.stereotype.Repository;
@Repository
public class StudentDAOImpl extends IBatisDAOSupport<StudentDAO> implements StudentDAO {
@Override
public List<StudentDBO> getAllStudent() throws Exception {
SqlSession session = this.getSqlSession();
try {
return this.getMapper(StudentDAO.class, session).getAllStudent();
} catch (Exception e) {
throw new Exception(e);
} finally {
this.closeSqlSession(session);
}
}
public void addStudent(Map<String, Object> paraMap) throws Exception {
SqlSession session = this.getSqlSession();
try {
this.getMapper(StudentDAO.class, session).addStudent(paraMap);
} catch (Exception e) {
throw new Exception(e);
} finally {
this.closeSqlSession(session);
}
}
public void delStudent(Map<String, Object> paraMap) throws Exception {
SqlSession session = this.getSqlSession();
try {
this.getMapper(StudentDAO.class, session).delStudent(paraMap);
} catch (Exception e) {
throw new Exception(e);
} finally {
this.closeSqlSession(session);
}
}
}
3.6 Service接口微微有些改变
为了演示给大家看 iBatis接受多个参数的例子因此我们把原来的如:login(String loginId, String loginPwd)这样的方法改成了public int validLogin(Map<String, Object> paraMap) throws Exception;这样的结构,请大家注意。
四、beta工程中的增加功能
4.1 增加了一个filter
在我们的web.xml文件中
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>org.sky.ssi.filter.LoginFilter</filter-class>
<init-param>
<param-name>exclude</param-name>
<param-value>/jsp/login/login.jsp,
/login.do
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filt