码迷,mamicode.com
首页 > 数据库 > 详细

09mybatis属性和数据库字段不匹配处理

时间:2017-06-20 20:20:25      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:res   bsp   tab   start   _id   book   query   engine   pac   

Book.java
id
name
price

book 表
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属性和数据库字段不匹配处理

标签:res   bsp   tab   start   _id   book   query   engine   pac   

原文地址:http://www.cnblogs.com/Mkady/p/7055949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!