09mybatis属性和数据库字段不匹配处理
Posted 归然
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了09mybatis属性和数据库字段不匹配处理相关的知识,希望对你有一定的参考价值。
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属性和数据库字段不匹配处理的主要内容,如果未能解决你的问题,请参考以下文章
MyBatis的一系列问题的处理(遍历Map集合和智能标签和属性和字段不一样的解决办法)