MyBatis-XML配置教程,这也太详细了吧!(3)
2021-05-28 16:10 升学就业帮
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?
useUnicode=true&characterEncoding=utf8"/
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/xyr/mapper/UserMapper.xml"/>
</mappers>
</configuration>
如果配置成功,在映射文件里面可以直接使用别名:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"//mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xyr.mapper.UserMapper">
<select id="selectOne" parameterType="int" resultType="user">
select * from user where id = #{id}
</select>
<select id="selectAll" resultType="user">
select * from user;
</select>
<insert id="saveUser" parameterType="user">
insert into user values(null, #{name}, #{password}, #{age});
</insert>
</mapper>
包扫描配置别名
<package name="com.xyr.domain"/>
name属性 : 对应要取别名的包,自动会为包下面的所有的类取别名,别名就是当前类名的简单名称
标签:
mybatis
官方微信公众号:掌酷门户(wapzknet)
相关资讯
新闻热点
精选美图