pom引入jar包

        
        
        
            org.mybatis
            mybatis
            3.4.6
        
        
        
            org.mybatis
            mybatis-spring
            1.3.2
        

spring配置

    
    

    
    
    
       
    

    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            false
        
        
        
                true
        
        
                true
        
        
                   select 1 from dual
        
        
                   300000
        
        
                   3
        
        
                   600000
        
    

    
    
        
        
        
    

    
    
        
        
    

    
    
        
    

    
    

jdbc.properties 数据库配置文件

###mysql表
jdbc.mysql.driverClassName=com.mysql.jdbc.Driver
#[ 测试用 ]
jdbc.mysql.url=jdbc:mysql://10.143.131.52:3306/test
jdbc.mysql.username=test
jdbc.mysql.password=test

#初始化连接大小
initialSize=3
#连接池最大数量
maxActive=50
#连接池最大空闲
maxIdle=10
#连接池最小空闲
minIdle=0
#获取连接最大等待时间
maxWait=-1

使用方法

例:查询

实体类

package com.dto;

public class TestDTO {

    private String id;
    private String name;
    private int age;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

}

DAO层

package com.daos;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.dto.TestDTO;

@Mapper
public interface TestDAO {

    @Select(" "
            )
    List list(@Param("tablename")String tablename, @Param("ages")List ages);
}

service层接口

package com.services;

import java.util.List;

import com.dto.TestDTO;

public interface TestService {

    /**
     * 信息
     * @param 
     */
    public List list(String tablename, List ages);

}

service层实现

package com.services.impl;

import java.util.List;

import com.daos.TestDAO;
import com.dto.TestDTO;
import com.services.TestService;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TestService implements TestService{

    @Autowired
    private TestDAO testDAO;

    /**
     * 信息
     * @param 
     */
    public List list(String tablename, List ages){
      try {
            return testDAO.list(tablename, ages);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ArrayList();
    }

}

controller层

package com.web;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.daos.TestDAO;
import com.dto.TestDTO;
import com.services.TestService;

/**
 * @功能 处理相关请求
 * @author zjw
 * 
 */
@Controller
@RequestMapping("/test")
public class TestController extends BaseController {
    private static final Logger log = LoggerFactory
            .getLogger(TestController.class);

    @Autowired
    private TestService testServiceImpl;

    /************************************* 任务管理 **********************************/
    /**
     * @functional 页面跳转
     * @param model
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/test.do")
    public String test(Model model, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        List ageList = new ArrayList<>();
        mobileList.add(80);
        List tests = testServiceImpl.list("t_test", ageList);
        System.out.println("tests:"+tests+":"+tests.size());
        return "/view/test/listTest";
    }

}