🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 修改UserMapper ```java package com.gosuncn.dao; import com.gosuncn.entity.User; public interface UserMapper { User findUserById(Integer id); } ``` ### 修改UserMapper.xml ```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="com.gosuncn.dao.UserMapper"> <select id="findUserById" parameterType="java.lang.Integer" resultType="com.gosuncn.entity.User"> select id, name, age, address from user where id = #{id} </select> </mapper> ``` ### 修改MainTest ```java package com.gosuncn; import com.gosuncn.dao.UserMapper; 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.InputStream; public class MainTest { public static void main(String[] args) throws Exception { InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml"); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sessionFactory.openSession(); UserMapper userMapper = sqlSession.getMapper(UserMapper.class); System.out.println(userMapper.findUserById(7)); sqlSession.close(); inputStream.close(); } } ```