使用mybatis时,如果映射器比较多的时候,采用xml配置就比较低效,这时可以采用MapperScannerConfigurer扫描指定的包,进行配置。
版本:spring 3.2.4 +mybatis3.2.2
package com.lzf;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface Mapper {
@Select("SELECT forum_id,forum_name, forum_desc FROM t_forum where id=#{userId}")
t_forum getT_forums(@Param("userId") long userId);
}
配置文件 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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context