MyBatis中出现列名与属性名不匹配如何解决

  介绍

这期内容当中小编将会给大家带来有关MyBatis中出现列名与属性名不匹配如何解决,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

MyBatis配置文件:

& lt; ? xml  version=?.0“,编码=癠TF-8" ?比;   & lt; ! DOCTYPE  configuration  PUBLIC “-//mybatis.org//DTD  Config  3.0//EN"   “http://mybatis.org/dtd/mybatis-3-config.dtd"比;   & lt; !,,   ,完成一个mybatis-config.xml的文件   →大敌;作用:配置连接数据库的所有需要的环境   ,必须连接到所有要使用的映射文件(ProductMapper.xml)   ,——比;   ,   & lt; !——configuration 根目录,——比;   & lt; configuration>   ,& lt; !——,引入(关联)db.properties文件,——祝辞,   ,& lt; properties 资源=癲b.properties"祝辞& lt;/properties>   ,   ,& lt; !——,配置别名:在MyBatis中为一个类取别名,配置别名是为了在对象映射文件中接收参数类型和返回参数类型时使用——比;   ,& lt; typeAliases>   ,& lt; !,,   ,设置这个包下面的所有类的别名   ,& lt; package  name=癱n.itsource.domain"/祝辞,   ,——比;   ,   ,& lt; !,,   ,设置单个类的别名,,别名:取的别名,类型:这个别名所对应的Java类,别名使用的时候与大小写无关   ,——比;=,& lt; typeAlias 别名“Product",类型=癱n.itsource.domain.Product"/比;   ,& lt;/typeAliases>   ,   ,& lt; !——,环境们:很多环境,,默认值:表示默认使用哪一个环境——比;   ,& lt; environments 默认=癲evelopment"比;   ,& lt; !——,单个环境:一个环境,,id:表示这个环境的名称——比;   ,& lt; environment  id=癲evelopment"比;   ,& lt; !——, transactionManager:事务管理器,(使用的JDBC事务管理器)——比;   ,& lt; transactionManager 类型=癑DBC"祝辞& lt;/transactionManager>   ,& lt; !——, MyBatis自帶汇集连接池(数据源),——比;   ,& lt; dataSource 类型=癙OOLED"比;   ,& lt; property  name=癲river",价值=https://www.yisu.com/zixun/" $ {db_driverClassname} "/>   <属性名=" url " value=" $ {db_url} "/>   <属性名="用户名" value=" $ {db_username} "/>   <属性名="密码" value=" $ {db_password} "/>                  <映射器>   <="cn/itsource/domain/ProductMapper映射器资源。xml "/>      

上面配置了别名,那么对象与映射文件中就可以直接使用别名,而不需要使用全限定名称

& lt; ? xml  version=?.0“,编码=癠TF-8" ?比;      & lt; !——,完成一个对象关系映射文件,,,   作用:一个对象的所有SQL都应该写在这个映射文件中,这个文件一般和我们的领域写在同一个包里面,取名为,   →大敌;域的名称+ Mapper.xml ——比;   ,& lt; ! DOCTYPE  mapper  PUBLIC “-//mybatis.org//DTD  mapper  3.0//EN"   “http://mybatis.org/dtd/mybatis-3-mapper.dtd"比;   ,   & lt; !——,名称空间:命名空间(每个Mapper必须有命名空间),——比;=& lt; mapper 名称空间“cn.itsource.domain.ProductMapper"祝辞   ,   ,& lt; !,,   选择:它才能里面写查询语句   id:才能查询语句的唯一标识(名称不能重复)   如才能何在,java代码中找到sql语句?,命名空间+ id    例才能子:cn.itsource.domain.ProductMapper.select   parameterType:才能传入的参数类型只除了MyBatis支持的类型,其它的类型都通通使用全限定名   resultType:才能返回的每一条数据的结果类型(结果类型写权限定名称,),查询功能使用   ,——比;   ,& lt; select  id=皊electOne", parameterType=癓ong", resultType=癙roduct"比;   ,select  *,得到product  where  id =, # {id}   ,& lt;/select>   ,   ,& lt; !——, resultType:表示返回的数据类型,——比;   ,& lt; select  id=皊electAll", resultType=癙roduct"比;   ,select  *,得到Product    ,& lt;/select>   ,   ,& lt; !——parameterType :表示传入参数(产品)。   ,useGeneratedKeys:是否需要获取主键   ,keyColumn:主键在数据库中的名称(不写的话默认名称和keyProperty一致)   ,keyProperty:对象中的属性(代表主键的那个属性)   ,——比;   ,& lt; insert  id=皊ave", parameterType=癙roduct",   ,useGeneratedKeys=皌rue" keyColumn=癷d", keyProperty=癷d"比;   ,insert  into  product  (productName, dir_id salePrice,供应商,品牌,截止,costPrice)   ,值(# {productName}, {dir_id} #, # {salePrice}, #{供应商},#{品牌},#{截止},# {costPrice})   ,& lt;/insert>   ,   ,& lt; !——, parameterType:接收参数没有写权限顶名称,使用的别名(简写),——比;   ,& lt; delete  id=癲elete", parameterType=發ong"比;   得到,delete  product  where  id =, # {id}   ,& lt;/delete>   ,   ,& lt; update  id=皍pdate", parameterType=癙roduct"比;   ,update  product  set  productName=# {productName}, dir_id=# {dir_id},   ,salePrice=# {salePrice},供应商=#{}供应商,品牌=#{品牌},截止=#{截止},costPrice=# {costPrice}   ,where  id =, # {id}   ,& lt;/update>   ,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

MyBatis中出现列名与属性名不匹配如何解决