标签:数据库 string type not 之间 证明 where pojo pack
package com.xuweiwei.mybatis.mapper; import com.xuweiwei.mybatis.pojo.Employee; import org.apache.ibatis.annotations.ResultType; import org.apache.ibatis.annotations.Select; public interface EmployeeMapper { @Select("select id as id,last_name as lastName,gender as gender,email as email from employee where id = #{id}") @ResultType(Employee.class) Employee getBemployeeById(Integer id); }
package com.xuweiwei.mybatis.test; import com.xuweiwei.mybatis.mapper.EmployeeMapper; import com.xuweiwei.mybatis.pojo.Employee; 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.InputStream; public class MybatisTest { /** * 测试增加 * * @throws IOException */ @Test public void test() throws IOException { /** * 创建SqlSessionFactory对象 */ String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); /** * 创建SqlSession */ SqlSession sqlSession = sqlSessionFactory.openSession(true); EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Employee employee = employeeMapper.getBemployeeById(1); System.out.println("====employee===:"+employee); Employee employee2 = employeeMapper.getBemployeeById(1); System.out.println("====employee2===:"+employee2); sqlSession.close(); } }
标签:数据库 string type not 之间 证明 where pojo pack
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/10206821.html