package com.landaiqing.test;

import com.landaiqing.entity.UserEntity;
import com.landaiqing.mapper.adminMapper;
import com.landaiqing.mapper.userMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;

public class Test02 {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        // 2.获取到获取到
        SqlSession sqlSession = sqlSessionFactory.openSession();
        // 3.根据 mapper id=getByUsers 执行该s  ql 语句 通过  sql语句得到我们的对象 orm
//        List<UserEntity> userEntitys = sqlSession.selectList("getByUsers", UserEntity.class);
        userMapper mapper = sqlSession.getMapper(userMapper.class);
//        System.out.println(mapper.login("666","666"));
        UserEntity userEntity = new UserEntity();
        userEntity.setQQ("888888");
        userEntity.setNickName("888");
        userEntity.setContent("8888");
        userEntity.setEmail("88888");
        userEntity.setUserId(10);
        userEntity.setReplyContent("000000000");
        Date time= new java.sql.Date(new java.util.Date().getTime());
        userEntity.setReplyDateTime(time);
        userEntity.setDateTime(time);
        System.out.println(mapper.update(userEntity));
        sqlSession.commit();
//        System.out.println(userEntitys);
        sqlSession.close();
    }
}
