spring-mybatis整合

spring-mybatis

2、spring-mybatis.xml











    
    
    
    




    
    
    
    
    
    
    
    




    
    
    
    

db.properties

jdbc.driverClassName=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql:///taobao?useUnicode=true&characterEncoding=utf-8

jdbc.username=root

jdbc.password=

3、UserMapper.xml






4、dao层

public interface UserDao {
    public User selectUserById(Integer uid);
}

5、service层

@Service //创建对象
public class UserServiceImpl implements IUserService {
    @Autowired //注入userdao的实现类
    private UserDao userDao;

    public User selectUserById(Integer uid) {
        return userDao.selectUserById(uid);
    }
}

6、测试类

public void testSelectUserById(){
    ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("spring-mybatis.xml");
    IUserService service = context.getBean(UserServiceImpl.class);
    User user = service.selectUserById(3);
    System.out.println(user);
}

1、导包


    
        junit
        junit
        4.12
        test
    
    
    
        org.springframework
        spring-core
        ${spring.version}
    
    
        org.springframework
        spring-context
        ${spring.version}
    
    
        org.springframework
        spring-context-support
        ${spring.version}
    
    
        org.springframework
        spring-aop
        ${spring.version}
    
    
        org.aspectj
        aspectjweaver
        1.8.10
    
    
        org.springframework
        spring-aspects
        ${spring.version}
    
    
        org.springframework
        spring-jdbc
        ${spring.version}
    
    
    
        org.mybatis
        mybatis
        3.4.5
    
    
        org.mybatis
        mybatis-spring
        1.3.1
    

    
    
        com.alibaba
        druid
        1.1.4
    

    
    
        mysql
        mysql-connector-java
        5.1.30
    
  

你可能感兴趣的:(spring-mybatis整合)