Book.java
Id
Name
Price
Book table
book_id
Book_name
Book_price
CREATE TABLE book (
book_id int unsigned auto_increment,
Book_name varchar (20),
Book_price Decimal (8,2),
Primary KEY (BOOK_ID)
) Engine=innodb Charset=utf8;
Bookmapper.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= "Com.fz.mapper.BookMapper" >
<resultmap id= "BK" type= "book" >
<id column= "book_id" property= "id"/>
<result property= "name" column= "Book_name"/>
<result property= "Price" column= "Book_price"/>
</resultMap>
<select id= "Queryall" resulttype= "book" resultmap= "BK" >
SELECT * FROM book
</select>
<select id= "page" parametertype= "map" resulttype= "book" >
SELECT * FROM book limit #{start},#{pagesize}
</select>
<select id= "Querybyid" resulttype= "book" statementtype= "PREPARED" >
SELECT * FROM book WHERE id = #{id}
</select>
<delete id= "Delete" statementtype= "PREPARED" >
Delete from book
</delete>
<delete id= "Deletebyid" parametertype= "int" statementtype= "PREPARED" >
Delete from book where id = #{id}
</delete>
<insert id= "Add" parametertype= "book" >
Insert into book values (Null,#{name},#{price})
</insert>
<insert id= "Save" parametertype= "Map" >
Insert into book values (Null,#{name},#{price})
</insert>
<update id= "Update" parametertype= "book" >
Update book set Name=#{name},price=#{price} where Id=#{id}
</update>
<update id= "Updatebyid" parametertype= "Map" >
Update book set Name=#{name},price=#{price} where Id=#{id}
</update>
<update id= "Updatebyname" parametertype= "Map" >
Update book set Price=#{price} where Name=#{name}
</update>
</mapper>
<resultmap id= "BK" type= "book" >
<id column= "book_id" property= "id"/>
<result property= "name" column= "Book_name"/>
<result property= "Price" column= "Book_price"/>
</resultMap>
<select id= "Queryall" resulttype= "book" resultmap= "BK" >
SELECT * FROM book
</select>
09mybatis attribute and database field mismatch processing