2023-09-02
UserMapper.xml模板
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="test"> <select id="selectAll" resultType="com.hh.pojo.User"> select * from tb_user </select> </mapper>
测试mybatis的代码
package com.hh; import com.hh.pojo.User; 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 java.io.IOException; import java.io.InputStream; import java.util.List; /** * @author hh * @version 1.0 * @DATE 2023-09-02 10:51:12 */ public class MybatisDemo { public static void main(String[] args) throws IOException { String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sqlSessionFactory.openSession(); List<User> list = sqlSession.selectList("test.selectAll"); System.out.println("list = " + list); sqlSession.close(); } }
标签:xml,UserMapper,ibatis,apache,org,mybatis,import From: https://www.cnblogs.com/isDaHua/p/17673327.html