下面来看java代码: Control层代码: package com.hl.usersmanager.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import com.hl.usersmanager.model.Users; import com.hl.usersmanager.service.IUserService; @Controller public class
使用Mybatis,你需要配置一个SqlMapConfig.xml的文件,主要用于配置sql语句的映射。当然,你也可以使用注解的方式直接将sql语句写入到class中,但我个人觉得sql语句后期优化的时候可能会时常调整。如果硬编码到class中,修改不方便。 好了,下面我们来看SqlMapConfig的配置: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!-- 这个配置使全局的映射器启用或禁用缓存 --> <
下面来看Spring的配置: applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/
废话不多说,我们先来看项目所需要的jar包: Spring3: org.springframework.aop-3.1.0.RELEASE.jar org.springframework.asm-3.1.0.RELEASE.jar org.springframework.aspects-3.1.0.RELEASE.jar org.springframework.beans-3.1.0.RELEASE.jar org.springframework.context-3.1.0.RELEASE.jar org.springframework.context.support-3.1.0.RELEASE.jar org.springframework.core-3.1.
经过两个星期的学习,基本掌握了Spring3+mybatis+mysql的整合。附件为我整理的demo源码。内容包括了Spring mvc、Spring aop、myBatis技术。其中Spring mvc、Spring aop都是采用注解方式实现的。 Demo 所需的Jar