spring-mybatis

spring-mybatis

spring-mybatis.xml

    
    

    
    

    
        
        
        
        
    

    
    
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
    

自行编写db文件

UserMapper.xml

    
    
    
        
    

dao层

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

service层

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

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

测试类

    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);
    }

导包

    
        
            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)