答案:否定的
因为即使没使用接口,也可以直接执行语句
bean类
package com.mu.bean;
import lombok.Data;
@Data
public class Imgs {
String id ;
String name;
String url;
}
mybatis.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="db.properties"/>
<!--别名-->
<typeAliases>
<package name="com.mu.bean"/>
</typeAliases>
<environments default="mysql1">
<environment id="mysql1">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="url" value="${db.url}"/>
<property name="driver" value="${db.driver}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapping/UserMapping.xml"/>
<mapper resource="mapping/ImgsMapping.xml"/>
</mappers>
</configuration>
***Mapping.xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mu">
<select id="queryAll" resultType="user">
select id,tel,password from user
</select>
</mapper>
Test测试
package com.mu;
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 org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
public class App {
@Test
public void test() throws IOException {
InputStream is = Resources.getResourceAsStream("mybatis.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
SqlSession sqlSession = sqlSessionFactory.openSession();
List<Object> objects = sqlSession.selectList("com.mu.queryAll");
System.out.println(objects);
}
}
在SqlSession里面有直接执行sql语句的方法,所以不需要再重新指定Mapping接口了