09mybatis attribute and database field mismatch processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.