MyBatis提供了多種方式來(lái)進(jìn)行查詢操作,包括根據(jù)名稱查詢數(shù)據(jù)。下面是使用MyBatis進(jìn)行根據(jù)名稱查詢數(shù)據(jù)的步驟:
public interface UserMapper {
User findByName(String name);
}
<select id="findByName" resultType="com.example.User">
SELECT * FROM user WHERE name = #{name}
</select>
<mappers>
<mapper resource="com/example/UserMapper.xml"/>
</mappers>
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
User user = userMapper.findByName("John");
System.out.println(user);
} finally {
sqlSession.close();
}
以上就是根據(jù)名稱查詢數(shù)據(jù)的基本步驟。你可以根據(jù)自己的實(shí)際需求進(jìn)行相應(yīng)的調(diào)整和修改。