Eclipse中引入MyBatis约束
约束文件
解压mybatis源码jar包,约束文件在mybatis-3.4.0-sources\org\apache\ibatis\builder\xml目录下
KEY
confi的key值
http://mybatis.org/dtd/mybatis-3-config.dtd
mapper的key值
http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd
在eclipse中配置
window->Preferences
搜索xml->点击xml catalog->点击add按钮,会弹出Add XML Catalog Element窗口->点击File System按钮->选择key的类型,并输入key值->点击ok即可
最后一步,申请保存并关闭
测试
mybatis.xml测试
mapper.xml测试
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> </configuration>
mapper.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="top.simba1949.mapper.UserMapper"> <select id="findAll" parameterType="User" resultType="User"> SELECT * FROM user </select> </mapper>