其他具体代码请访问-》mybatis的快速入门
1.在mybatis核心配置文件SqlMapperConfig.xml中配置别名
<!-- 定义别名-->
<typeAliases>
<typeAlias type="com.hao.domain.User" alias="user"/>
</typeAliases>
2.UserMapper.xml中的parameterType就不用再写User类的全限定名
<?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="userMapper">
<select id="findAll" resultType="user"><!--resultType意思是将查询的结果封装到哪个实体类中 -->
select * from user
</select>
<!-- 插入操作-->
<insert id="save" parameterType="user">
insert into user values(#{id},#{username},#{password})
</insert>
<!-- 更新操作-->
<update id="update" parameterType="user">
update user set username=#{username},password=#{password} where id=#{id}
</update>
<!-- 删除操作-->
<delete id="delete" parameterType="int">
delete from user where id=#{id}
</delete>
</mapper>