1.mapper

<select id="selectStudentCount" parameterType="String"
        resultType="Integer">
    select count(*) from student where STU_ID= #{value}
</select>

2,java

public interface StudentMapper {
    public void insertStudent(Student student);
    public void deteteStudent(String id);
    public void updateStudent(Student student);
    public List<Student> selectStudentByQueryVo(QueryVo queryVo);
    public List<Student> selectStudent(String id);
    public Integer selectStudentCount(String id);
}

3,test

@Test
public void testInteger() throws IOException
{
    //读取配置信息
    String resource="applicationContext.xml";
    //根据配置文件构建sqlsessionFactory
    InputStream in=Resources.getResourceAsStream(resource);
    //通过sqlsessionFactory创建sqlsession
    SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(in);
    SqlSession sqlSession =sqlSessionFactory.openSession(); 
    //获取接口类
    StudentMapper studentMapper=sqlSession.getMapper(StudentMapper.class);
    Integer count=studentMapper.selectStudentCount("1")    ;
    List<Student> student=studentMapper.selectStudent("1");
    System.out.println(count);
    System.out.println(student);
    sqlSession.close();
}

 

posted on 2018-06-12 08:37  song.yan  阅读(223)  评论(0编辑  收藏  举报