package transaction;

import com.Config.AppConfig1;
import com.Domain.Context;
import com.Domain.User;
import com.Mapper.UserMapper;
import com.Service.UserService;
import com.StartUp;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * Created by lqt
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {StartUp.class})
public class MybatisTest {
  private static final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig1.class);
  @Autowired
  UserService userService;
  //=====================================mybatis 2 homework start=============================================================

  /**
   * 提供单对象，和多对象参数， sql打印功能 => 查询
   */
  @Test
  public void selectUser() {
    String name = "hcj";
    User user = userService.selectUser(name, "123");
    System.out.println(user);
  }

  /**
   * 提供单对象，， sql打印功能 => 修改删除，新增，  注意： 目前多对象参数暂不支持
   */
  @Test
  public void insertUser() {
    User user = new User();
    user.setUsername("张三");
    user.setPassword("000000");
    user.setEnabled(true);
    userService.insertUserNoObject(user);
  }
}
