你的位置:首页 > ASP.net教程

[ASP.net教程]SpringMVC3+Mybatis3(登录及CRUD操作)


官网:http://code.google.com/p/mybatis/ 
参考资料 
1 兼顾效率,iBatis一些非见用法(10条) 
http://lavasoft.blog.51cto.com/62575/202886/ 
2 整合Mybatis与Spring3 
http://www.iteye.com/topic/1018134 
一 环境:XP3+Oracle10g+MyEclipse6+(Tomcat or WebLogic92)+JDK1.5 
二 工程文件: Spring3+MyIbatis3 
工程图片: 
 
jar下载:http://dl.iteye.com/topics/download/d209389e-ecac-390e-85c7-c08849f50348 
三 具体代码如下: 
1 数据库文件 

Java代码  收藏代码

  1. create table USERS  
  2. (  
  3.   id       VARCHAR2(50) not null,  
  4.   name     VARCHAR2(50),  
  5.   age      INTEGER,  
  6.   sex      VARCHAR2(1),  
  7.   address  VARCHAR2(200),  
  8.   password VARCHAR2(20)  
  9. )  
  10. insert into users (id,name,age,sex,address,password)VALUES("123456789","sprng",23,"1","北京大学","123");  



2 Java相关文件 
A UserMapper.java 

Java代码  收藏代码

  1. package com.liuzd.ssm.mapper;  
  2.   
  3. import java.util.List;  
  4. import com.liuzd.ssm.entity.User;  
  5.   
  6. public interface UserMapper{  
  7.       
  8.     public int checkUserExits(User user);         
  9.     public void addUser(User user);       
  10.     public void editUser(User user);      
  11.     public void delUser(String userId);   
  12.     public List<User> getUserList();    
  13.     public User getUserByUid(String userId);      
  14. }  


B UserMapper.

Java代码  收藏代码

  1. <?"1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  4. <mapper namespace="com.liuzd.ssm.mapper.UserMapper">        
  5.   
  6.    <resultMap type="com.liuzd.ssm.entity.User" id="userMap">  
  7.      <id property="id" column="id"/>  
  8.      <result property="name" column="name"/>  
  9.      <result property="age" column="age"/>  
  10.      <result property="sex" column="sex"/>  
  11.      <result property="address" column="address"/>  
  12.      <result property="password" column="password"/>  
  13.    </resultMap>      
  14.      
  15.       
  16.   <select id="checkUserExits"  parameterType="com.liuzd.ssm.entity.User" resultType="int">  
  17.     <![CDATA[    
  18.        select count(*) from users where name=#{name} and password=#{password}      
  19.     ]]>   
  20.   </select>  
  21.     
  22.   <select id="getUserList"  resultType="java.util.List" resultMap="userMap">  
  23.      <![CDATA[   
  24.      select * from users  
  25.      ]]>   
  26.   </select>  
  27.    
  28.     
  29.   <select id="getUserByUid" parameterType="string" resultType="com.liuzd.ssm.entity.User">  
  30.     <![CDATA[   
  31.       select * from users where id=#{id}    
  32.     ]]>   
  33.   </select>  
  34.     
  35.   <update id="editUser" parameterType="com.liuzd.ssm.entity.User">  
  36.     <![CDATA[   
  37.      update users set name=#{name},age=#{age},sex=#{sex},address=#{address},password=#{password} where id=#{id}  
  38.      ]]>  
  39.   </update>  
  40.   
  41.   <insert id="addUser" parameterType="com.liuzd.ssm.entity.User">    
  42.      <![CDATA[    
  43.      insert into users (id,name,age,sex,address,password)VALUES(#{id},#{name},#{age},#{sex},#{address},#{password})   
  44.       ]]>  
  45.   </insert>  
  46.     
  47.    <delete id="delUser" parameterType="string">  
  48.       <![CDATA[  
  49.         delete users where id=#{id}  
  50.       ]]>  
  51.    </delete>     
  52.   
  53. </mapper>  



C UserService.java 

Java代码  收藏代码

  1. package com.liuzd.ssm.service;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.springframework.beans.factory.annotation.Autowired;  
  6. import org.springframework.stereotype.Service;  
  7.   
  8.   
  9. import com.liuzd.ssm.entity.User;  
  10. import com.liuzd.ssm.mapper.UserMapper;  
  11.   
  12. @Service("userService")  
  13. public class UserService {  
  14.           
  15.     @Autowired  
  16.     private UserMapper userMapper;    
  17.   
  18.     public void addUser(User user) {  
  19.         this.userMapper.addUser(user);    
  20.     }  
  21.       
  22.     public int checkUserExits(User user) {            
  23.         return this.userMapper.checkUserExits(user);          
  24.     }  
  25.   
  26.     public void delUser(String userId) {  
  27.         this.userMapper.delUser(userId);  
  28.     }  
  29.   
  30.   
  31.     public User getUserByUid(String userId) {         
  32.         return (User)this.userMapper.getUserByUid(userId);  
  33.     }  
  34.   
  35.     public List<User> getUserList() {       
  36.         return (List<User>)this.userMapper.getUserList();  
  37.     }     
  38.   
  39.     public void editUser(User user) {         
  40.         this.userMapper.editUser(user);  
  41.     }  
  42.       
  43. }  



D WEB层调用代码 

a LoginController.java 

Java代码  收藏代码

  1. package com.liuzd.ssm.web;  
  2.   
  3. import java.util.List;  
  4.   
  5. import javax.annotation.Resource;  
  6. import javax.servlet.http.HttpServletRequest;  
  7. import javax.servlet.http.HttpServletResponse;  
  8.   
  9. import org.springframework.stereotype.Controller;  
  10. import org.springframework.ui.Model;  
  11. import org.springframework.web.bind.annotation.ModelAttribute;  
  12. import org.springframework.web.bind.annotation.PathVariable;  
  13. import org.springframework.web.bind.annotation.RequestMapping;  
  14. import org.springframework.web.bind.annotation.RequestMethod;  
  15. import org.springframework.web.servlet.ModelAndView;  
  16.   
  17. import com.liuzd.ssm.entity.User;  
  18. import com.liuzd.ssm.service.UserService;  
  19.   
  20. @Controller  
  21. @RequestMapping("/login")  
  22. public class LoginController {  
  23.       
  24.     private UserService userService;  
  25.       
  26.   
  27.     public UserService getUserService() {  
  28.         return userService;  
  29.     }  
  30.       
  31.     @Resource  
  32.     public void setUserService(UserService userService) {  
  33.         this.userService = userService;  
  34.     }     
  35.       
  36.   
  37.     @SuppressWarnings("unchecked")  
  38.     @RequestMapping("add")  
  39.     //@ModelAttribute 可加可不加,url: http://127.0.0.1:8088/ssm/user/add.do  
  40.     public String login(User user, HttpServletRequest req, HttpServletResponse response) {  
  41.         // 此处调用服务层进行相应的业务操作       
  42.         // 传递对象于下一页面  
  43.         req.setAttribute("user", user);  
  44.         // 调用服务层进行验证用户,此处只演示功能  
  45.         int usize  = getUserService().checkUserExits(user);   
  46.         System.out.println("用户信息: " + user + ",usize: "+usize);       
  47.         if (usize > 0) {               
  48.             //return "success";  
  49.             List<User> useralls = this.getUserService().getUserList();      
  50.             req.setAttribute("userList", useralls);  
  51.             return "userList";  
  52.         }  
  53.         return "error";  
  54.     }  
  55.   
  56.     @SuppressWarnings("unchecked")  
  57.     // @RequestMapping(params= "method=add2",method=RequestMethod.POST)  
  58.     // 定义method方法不是必须的  
  59.     @RequestMapping(params = "method=add2")  
  60.     public ModelAndView login2(@ModelAttribute("user")User user, HttpServletRequest req, HttpServletResponse response) {  
  61.         // 使用ModelAndView保存对象于下一页面  
  62.         ModelAndView model = new ModelAndView();  
  63.         model.addObject("user", user);  
  64.         // 调用服务层进行验证用户,此处只演示功能  
  65.         int usize  = getUserService().checkUserExits(user);   
  66.         System.out.println("用户信息2: " + user + ",usize: "+usize);          
  67.         if (usize > 0) {                   
  68.             List<User> useralls = this.getUserService().getUserList();                  
  69.             model.addObject("userList", useralls);  
  70.             model.setViewName("userList");            
  71.         } else {  
  72.             model.addObject("msg","用户或者密码错误!");       
  73.             model.setViewName("error");  
  74.         }  
  75.         return model;  
  76.     }     
  77.       
  78.     @RequestMapping(value="add3/{name}/{password}",method=RequestMethod.GET)  
  79.     public String login3(@PathVariable("name") String name,@PathVariable("password") String pwd,Model model) {    
  80.         User user = new User();  
  81.         user.setName(name);  
  82.         user.setPassword(pwd);  
  83.         model.addAttribute("user",user);                  
  84.         // 调用服务层进行验证用户,此处只演示功能  
  85.         int usize  = getUserService().checkUserExits(user);   
  86.         System.out.println("用户信息3: "+user + ",size: " + usize);  
  87.         if (usize > 0) {   
  88.             return "success";  
  89.         }  
  90.         //放入model默认把参数存于请求  
  91.         model.addAttribute("msg","用户或者密码错误!");        
  92.         return  "error";  
  93.           
  94.         /** 
  95.          * 重定向JSP页面,走出了springmvc配置的view(jsp) 
  96.          * 因为这样说明:model.addAttribute("msg","用户或者密码错误!");  
  97.          * 获取不到值了 
  98.          * 不加上.jsp就是这样:http://127.0.0.1:8080/Spring3-Login-Annotaction/index?msg=%E7...      
  99.          * */         
  100.         //返回到页面是乱码在页面中用${msg}获取不到值,用request.getParams("msg");为乱码  
  101.         //return "redirect:index.jsp?msg=用户或者密码错误!";          
  102.     }  
  103. }  



b UserController.java 

Java代码  收藏代码

  1. package com.liuzd.ssm.web;  
  2.   
  3. import java.util.List;  
  4.   
  5. import javax.annotation.Resource;  
  6.   
  7. import org.springframework.stereotype.Controller;  
  8. import org.springframework.web.bind.annotation.PathVariable;  
  9. import org.springframework.web.bind.annotation.RequestMapping;  
  10. import org.springframework.web.bind.annotation.SessionAttributes;  
  11. import org.springframework.web.servlet.ModelAndView;  
  12.   
  13. import com.liuzd.ssm.entity.User;  
  14. import com.liuzd.ssm.service.UserService;  
  15.   
  16. @Controller  
  17. @RequestMapping("/user")  
  18. @SessionAttributes("userList")  
  19. public class UserController {  
  20.       
  21.     private UserService userService;  
  22.       
  23.   
  24.     public UserService getUserService() {  
  25.         return userService;  
  26.     }  
  27.       
  28.     @Resource  
  29.     public void setUserService(UserService userService) {  
  30.         this.userService = userService;  
  31.     }     
  32.   
  33.       
  34.     @RequestMapping("/userList")  
  35.     public ModelAndView userList(){  
  36.         /** 
  37.          * 想要在页面展现数据,必须返回ModelAndView类型,返回String是不能获取数据的 
  38.          * */  
  39.         ModelAndView mv = new ModelAndView();  
  40.         List<User> users = this.getUserService().getUserList();                 
  41.         mv.addObject("userList",users);               
  42.         mv.setViewName("userList");           
  43.         return mv;  
  44.     }  
  45.       
  46.       
  47.       
  48.     @RequestMapping("/addUser")  
  49.     public ModelAndView addUser(User user){  
  50.         System.out.println("ADD USER: "+ user);   
  51.         this.userService.addUser(user);       
  52.         return userList();  
  53.     }  
  54.       
  55.     @RequestMapping("/toAddUser")  
  56.     public String toAddUser(){        
  57.         return "addUser";  
  58.     }  
  59.       
  60.     @RequestMapping("/delUser/{id}")  
  61.     public ModelAndView delUser(@PathVariable("id") String id){  
  62.         this.userService.delUser(id);  
  63.         return userList();  
  64.     }  
  65.       
  66.     @RequestMapping("/getUser/{id}")  
  67.     public ModelAndView getUser(@PathVariable("id") String id){  
  68.         User user = this.userService.getUserByUid(id);  
  69.         ModelAndView mv = new ModelAndView("updateUser");  
  70.         mv.addObject("user",user);  
  71.         return mv;  
  72.     }     
  73.       
  74.     @RequestMapping("/updateUser")  
  75.     public ModelAndView editUser(User user){      
  76.         System.out.println("编辑: "+user);  
  77.         this.userService.editUser(user);  
  78.         return userList();  
  79.     }         
  80.       
  81. }  



3 JSp文件 
A index.jsp 

Java代码  收藏代码

  1. <%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  3. <html>  
  4.   <head>  
  5.     <%@ include file="/common/meta.jsp"%>  
  6.   </head>    
  7.   <body>  
  8.      <form action="${pageContext.request.contextPath}/login/add.do" method="post">  
  9.          姓名: <input type="text" name="name" id="name"><br>  
  10.          密码: <input type="password" name="password" id="password"><br>  
  11.          <input type="submit" value="Login">  
  12.      </form>  <br>  
  13.      <form action="${pageContext.request.contextPath}/login.do?method=add2" method="post">  
  14.          姓名: <input type="text" name="name" id="name"><br>  
  15.          密码: <input type="password" name="password" id="password"><br>  
  16.          <input type="submit" value="Login2">  
  17.      </form>    
  18.       <br>  
  19.      <a href="${pageContext.request.contextPath}/login/add3/spring/spring.do">Spring MVC RESL风格</a>  
  20.   </body>  
  21. </html>  


B addUser.jsp 

Java代码  收藏代码

  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
  2. <%@ page import="org.apache.commons.lang3.RandomStringUtils"%>  
  3. <%  
  4. String id = RandomStringUtils.randomAlphanumeric(32);  
  5.  %>  
  6. <html>  
  7. <head>  
  8.     <title>用户信息</title>  
  9. </head>  
  10. <body>  
  11. <form action="${pageContext.request.contextPath}/user/addUser.do" method="post">  
  12. <br>  
  13.   <table>  
  14.       <tr>         
  15.         <td>  
  16.         <input name="id" type="hidden" value="<%=id%>">  
  17.           姓名: <input name="name">                   
  18.          </td>  
  19.       </tr>  
  20.       <tr>         
  21.         <td>  
  22.           年龄: <input name="age">        
  23.         </td>  
  24.       </tr>  
  25.       <tr>          
  26.         <td>  
  27.           性别: <select name="sex">  
  28.             <option value="1">男</option>  
  29.             <option value="2">女</option>  
  30.           </select>  
  31.         </td>  
  32.       </tr>  
  33.       <tr>          
  34.         <td>  
  35.            密码: <input name="password">        
  36.         </td>   
  37.       </tr>  
  38.       <tr>         
  39.         <td>  
  40.           地址:<input name="address"/>  
  41.         </td>  
  42.       </tr>  
  43.       <tr>  
  44.         <td align="right">  
  45.          <input type="submit" vlaue="保存"/>  
  46.         </td>  
  47.       </tr>  
  48.     </table>  
  49. </form>  
  50. <br>  
  51. <a href="${pageContext.request.contextPath}/index.jsp">返回主页</a><br>  
  52. <a href="${pageContext.request.contextPath}/user/userList.do">返回显示</a>  
  53. </body>  
  54. </html>  



C updateUser.jsp 

Java代码  收藏代码

  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
  2. <html>  
  3. <head>  
  4.     <title>编辑用户信息</title>  
  5. </head>  
  6. <body>  
  7. <form action="${pageContext.request.contextPath}/user/updateUser.do" method="post">  
  8. <br>  
  9.   <table>  
  10.       <tr>         
  11.         <td>  
  12.         <input name="id" type="hidden" value="${user.id}">  
  13.           姓名: <input name="name" value="${user.name}">                   
  14.          </td>  
  15.       </tr>  
  16.       <tr>         
  17.         <td>  
  18.           年龄: <input name="age" value="${user.age}">        
  19.         </td>  
  20.       </tr>  
  21.       <tr>          
  22.         <td>  
  23.           性别: <select name="sex">  
  24.             <option value="1" ${user.sex eq "1"  ? "selected" : ""}>男</option>  
  25.             <option value="2" ${user.sex eq "2"  ? "selected" : ""}>女</option>  
  26.           </select>  
  27.         </td>  
  28.       </tr>  
  29.       <tr>          
  30.         <td>  
  31.            密码: <input name="password" value="${user.password}">        
  32.         </td>   
  33.       </tr>  
  34.       <tr>         
  35.         <td>  
  36.           地址:<input name="address" value="${user.address}"/>  
  37.         </td>  
  38.       </tr>  
  39.       <tr>  
  40.         <td align="right">  
  41.          <input type="submit" vlaue="保存"/>  
  42.         </td>  
  43.       </tr>  
  44.     </table>  
  45. </form>  
  46. <br>  
  47. <a href="${pageContext.request.contextPath}/index.jsp">返回主页</a><br>  
  48. <a href="${pageContext.request.contextPath}/user/userList.do">返回集合显示</a>  
  49. </body>  
  50. </html>  



D userList.jsp 

Java代码  收藏代码

  1. <%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>  
  2. <%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>  
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  4. <html>  
  5.   <head>  
  6.     <%@ include file="/common/meta.jsp"%>  
  7.   </head>    
  8.   <body>  
  9.       <table width="60%" border="1" cellpadding="0" align="center">  
  10.             <thead>  
  11.                 <tr>  
  12.                     <th style="cursor: hand;" title="按姓名进行排序" onclick="sortPage('name')" valign="top">  
  13.                         姓名  
  14.                     </th>  
  15.                     <th style="cursor: hand;" title="按年龄进行排序" onclick="sortPage('age')" valign="top">  
  16.                         年龄  
  17.                     </th>  
  18.                     <th style="cursor: hand;" title="按性别进行排序" onclick="sortPage('sex')" valign="top">  
  19.                         性别  
  20.                     </th>  
  21.                     <th style="cursor: hand;" title="按地址进行排序" onclick="sortPage('address')" valign="top">  
  22.                         地址  
  23.                     </th>  
  24.                     <th style="cursor: hand;" >  
  25.                         操作  
  26.                     </th>  
  27.                 </tr>  
  28.             </thead>  
  29.             <tbody>             
  30.   
  31.                 <c:forEach items="${userList}" var="user">  
  32.                     <tr align="center">  
  33.                         <td>  
  34.                             ${user.name}  
  35.                         </td>  
  36.                         <td>  
  37.                             ${user.age}  
  38.                         </td>  
  39.                         <td>  
  40.                             ${user.sex eq 1 ? "男" : user.sex eq 2 ? "女" : "未知"}  
  41.                         </td>  
  42.                         <td>  
  43.                             ${user.address}  
  44.                         </td>  
  45.                         <td>  
  46.                             <a  
  47.                                 href="${pageContext.request.contextPath}/user/toAddUser.do">添加</a>  
  48.                             |  
  49.                             <a  
  50.                                 href="${pageContext.request.contextPath}/user/getUser/${user.id}.do">编辑</a>  
  51.                             |  
  52.                             <a  
  53.                                 href="${pageContext.request.contextPath}/user/delUser/${user.id}.do">删除</a>  
  54.                         </td>  
  55.                     </tr>  
  56.                 </c:forEach>  
  57.   
  58.   
  59.             </tbody>  
  60.         </table>  
  61.         <br>  
  62.         <a href="${pageContext.request.contextPath}/index.jsp">返回</a>         
  63.   </body>  
  64. </html>  



4 配置文件 
a web.Java代码  收藏代码

  1. <?"1.0" encoding="UTF-8"?>  
  2. <web-app version="2.5" "http://java.sun.com/
  3.     "http://www.w3.org/2001/
  4.     xsi:schemaLocation="http://java.sun.com/
  5.     http://java.sun.com/
  6.       
  7.     <context-param>  
  8.       <param-name>webAppRootKey</param-name>  
  9.       <param-value>ssm.root</param-value>  
  10.      </context-param>  
  11.   
  12.     <context-param>  
  13.         <param-name>  
  14.             contextConfigLocation  
  15.         </param-name>  
  16.         <param-value>  
  17.             classpath*:applicationContext.
  18.         </param-value>  
  19.     </context-param>  
  20.       
  21.     <context-param>  
  22.        <param-name>log4jConfigLocation</param-name>  
  23.        <param-value>/WEB-INF/classes/log4j.properties</param-value>  
  24.     </context-param>   
  25.       
  26.      <context-param>  
  27.       <param-name>log4jRefreshInterval</param-name>  
  28.       <param-value>60000</param-value>  
  29.      </context-param>   
  30.      <context-param>  
  31.         <param-name>log4jExposeWebAppRoot</param-name>  
  32.         <param-value>false</param-value>  
  33.     </context-param>  
  34.       
  35.     <listener>  
  36.         <listener-class>  
  37.             org.springframework.web.context.ContextLoaderListener  
  38.         </listener-class>  
  39.     </listener>     
  40.       
  41.     <listener>  
  42.        <listener-class>  
  43.             org.springframework.web.util.Log4jConfigListener  
  44.        </listener-class>  
  45.     </listener>   
  46.   
  47.     <filter>  
  48.         <filter-name>encodingFilter</filter-name>  
  49.         <filter-class>  
  50.             org.springframework.web.filter.CharacterEncodingFilter  
  51.         </filter-class>  
  52.         <init-param>  
  53.             <param-name>encoding</param-name>  
  54.             <param-value>UTF-8</param-value>  
  55.         </init-param>  
  56.         <init-param>     
  57.             <param-name>forceEncoding</param-name>     
  58.             <param-value>false</param-value>     
  59.         </init-param>    
  60.     </filter>  
  61.   
  62.     <filter-mapping>  
  63.         <filter-name>encodingFilter</filter-name>  
  64.         <url-pattern>*.do</url-pattern>  
  65.     </filter-mapping>  
  66.       
  67.     <filter-mapping>  
  68.         <filter-name>encodingFilter</filter-name>  
  69.         <url-pattern>*.jsp</url-pattern>  
  70.     </filter-mapping>  
  71.   
  72.     <servlet>  
  73.         <servlet-name>springmvc</servlet-name>  
  74.         <servlet-class>  
  75.             org.springframework.web.servlet.DispatcherServlet  
  76.         </servlet-class>        
  77.         <init-param>  
  78.             <param-name>contextConfigLocation</param-name>                             
  79.              <param-value>classpath:springmvc.
  80.         </init-param>   
  81.         <load-on-startup>1</load-on-startup>  
  82.     </servlet>  
  83.   
  84.     <servlet-mapping>  
  85.         <servlet-name>springmvc</servlet-name>  
  86.         <url-pattern>*.do</url-pattern>  
  87.     </servlet-mapping>  
  88.   
  89.     <!-- weblogic配置数据源需要  
  90.      <resource-ref>   
  91.       <description>s2sh</description>   
  92.       <res-ref-name>s2sh</res-ref-name>   
  93.       <res-type>javax.sql.DataSource</res-type>   
  94.       <res-auth>Container</res-auth>   
  95.     </resource-ref>   
  96.          -->  
  97.   
  98.     <welcome-file-list>  
  99.         <welcome-file>index.jsp</welcome-file>  
  100.     </welcome-file-list>  
  101.   
  102. </web-app>  



b applicationContext.Java代码  收藏代码

    1. <?"1.0" encoding="UTF-8"?>  
    2. <beans "http://www.springframework.org/schema/beans"  
    3.     "http://www.w3.org/2001/
    4.     "http://www.springframework.org/schema/context"  
    5.     "http://www.springframework.org/schema/aop"  
    6.     "http://www.springframework.org/schema/tx"  
    7.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
    8.            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    9.            http://www.springframework.org/schema/context  
    10.            http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    11.            http://www.springframework.org/schema/aop  
    12.            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
    13.            http://www.springframework.org/schema/tx   
    14.            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  
    15.              
    16.     <context:annotation-config />  
    17.     <context:component-scan base-package="com.liuzd.ssm.service" />  
    18.       
    19.     <bean  
    20.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
    21.         <property name="locations">  
    22.             <value>classpath:jdbc.properties</value>  
    23.         </property>  
    24.     </bean>  
    25.       
    26.       
    27.     <bean id="dataSource"    class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">                
    28.         <property name="driverClassName" value="${jdbc.driverClassName}"/>  
    29.         <property name="url" value="${jdbc.url}" />             
    30.         <property name="username" value="${jdbc.username}" />  
    31.         <property name="password" value="${jdbc.password}" />  
    32.     </bean>  
    33.       
    34.     <!--   
    35.     <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">     
    36.         <property name="jndiName">  
    37.             <value>${JNDI}</value>  
    38.         </property>    
    39.         <property name="resourceRef">  
    40.             <value>${RESOURCEREF}</value>  
    41.         </property>         
    42.         <property name="jndiEnvironment">   
    43.          <props>   
    44.             <prop key="java.naming.provider.url">${Context.PROVIDER_URL}</prop>   
    45.             <prop key="java.naming.factory.initial">${Context.INITIAL_CONTEXT_FACTORY}</prop>            
    46.          </props>      
    47.        </property>    
    48.    </bean> -->   
    49.     
    50.   
    51.     <!-- define the SqlSessionFactory, notice that configLocation is not needed when you use MapperFactoryBean -->  
    52.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
    53.         <property name="dataSource" ref="dataSource" />    
    54.         <!--   
    55.          <property name="configLocation" value="classpath*:mybatis-config.
    56.          -->                             
    57.     </bean>  
    58.   
    59.     <!-- scan for mappers and let them be autowired -->  
    60.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
    61.         <property name="basePackage" value="com.liuzd.ssm.mapper" />  
    62.     </bean>  
    63.   
    64. </beans>