package Test;
import com.itheima.pojo.Users;
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 org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import java.util.Scanner;
public class BooksTest {
@Test
public void userFindByIdTest(){
String resources="mybatis-config.xml";
//创建流
Reader reader=null;
try {
reader= Resources.getResourceAsReader(resources);
}catch (IOException e){
e.printStackTrace();
}
SqlSessionFactory sqlMapper=new SqlSessionFactoryBuilder().build(reader);
SqlSession session=sqlMapper.openSession();
Scanner scanner=new Scanner(System.in);
Users users=new Users();
System.out.println("请输入用户名:");
String name=scanner.nextLine();
System.out.println("请输入密码:");
String pwd=scanner.nextLine();
scanner.close();
users.setLoginId(name);
users.setLoginPwd(pwd);
int rowCount=session.selectOne("doLogin",users);
if (rowCount>0){
System.out.println("登陆成功!");
}else{
System.out.println("登录失败!");
}
session.close();
}
}