在Student.xml中插入如下代码:

    <!-- parameterClass代表要传入的参数类型  -->
<select id="SelectStudentById" parameterClass="int" resultClass="Student">
select *
from student
where id=#id#
</select>

然后在junit中进行测试:

1     @Test
2 public void queryStudentById() throws Exception{//根据Id查学生
3 Reader reader=Resources.getResourceAsReader("SqlMapConfig.xml");//读取总配置文件
4 SqlMapClient sqlmapclient=SqlMapClientBuilder.buildSqlMapClient(reader);//创建SqlMapClient来操作数据库
5 reader.close();
6 Student student=(Student) sqlmapclient.queryForObject("SelectStudentById",4);//调用我们写在xml中的sql语句
7 System.out.println(student);
8 }

打印如下结果:

4    brian    100.0





相关文章:

  • 2021-10-02
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-07-15
  • 2021-10-28
猜你喜欢
  • 2021-07-18
  • 2021-12-16
  • 2022-01-24
  • 2021-11-23
  • 2021-10-24
  • 2021-09-10
相关资源
相似解决方案