设为首页 加入收藏

TOP

通向架构师的道路(第二十天)万能框架spring(二)maven结合spring与ibatis(五)
2018-03-14 09:00:25 】 浏览:846
Tags:通向 架构 师的 道路 第二十 万能 框架 spring maven 结合 ibatis
<![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
首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用 partclone 备份磁盘分区 下一篇使用foremost恢复已删除文件

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目