Java-Mybatis核心配置
- mybatis-config.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="jdbc.properties"/>
<settings>
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
<typeAliases>
<package name="cn.cnyasin.pojo"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="cn/cnyasin/dao/UserMapper.xml"/>
</mappers>
</configuration>
- UserMapper.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="cn.cnyasin.dao.UserMapper">
<select id="getOne" resultType="cn.cnyasin.pojo.User">
select * from user where id = #{id}
</select>
<insert id="addOne" parameterType="cn.cnyasin.pojo.User">
insert into user (`username`,`email`,`password`,`created_at`) values (#{username}, #{email}, #{password}, #{created_at})
</insert>
<update id="updateOne" parameterType="cn.cnyasin.pojo.User">
update user set balance = #{balance} where id = #{id};
</update>
<delete id="deleteOne">
delete from user where id = #{id}
</delete>
<resultMap id="userListMap" type="cn.cnyasin.pojo.User"/>
</mapper>
|