Questions about MyBatis There is no getter for property named ' User_name ' in ' Class Com.bky.model. Instance class '

Source: Internet
Author: User

Now the popular SSM (Spring + struts2 + myBatis) Persistence layer MyBatis is the need to configure the mapper, found a demo connection database is MySQL then modified to become a connection to Oracle

When everything's ready to run, it's time to do the insert operation. My table is b field is ID, user_name, password instance class field is ID, Username,password,

Here is a user_name and username had a headache for the afternoon, and later found the fishy,

There is no getter for property named ' User_name ' in ' Class com.bky.model.b '

Code:

Entity class B

Package Com.bky.model;public class B {    private Long ID;    Private String userName;        private String password;    Public Long GetId () {return ID;} public void SetId (Long id) {this.id = id = = null? Null:id;} Public String GetUserName () {return userName;} public void Setusername (String userName) {this.username = UserName;} Public String GetPassword () {return password;} public void SetPassword (String password) {this.password = password = = null? Null:password.trim ();}}


Mapper. 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.bky.dao.BMapper" >  <resultmap id= "Baseresultmap" type= "com.bky.model.b" >    <id column= "id" property= "id" jdbctype= "INTEGER"/>    <result column= "user_name" property= "UserName" jdbctype= "varchar"/>    <result column= "PASSWORD" property= "PASSWORD" jdbctype= "varchar"/>  </ resultmap>  <sql id= "Base_column_list" >    ID, user_name, PASSWORD  </sql>
<span style= "White-space:pre" ></span><!--Let's focus on this.
<span style= "White-space:pre" ></span>user_name is a table field and behind <span style= "font-family:arial, Helvetica, Sans-serif; " >#{user_name,jdbctype=varchar} Here is wrong should be written </span><span style= "Font-family:arial, Helvetica, Sans-serif;" >#{username,jdbctype=varchar} should be a property value ah look for a good bitter ah, this is a waste of the afternoon, but still solved, a lot of people at the beginning of Baidu is the property name is wrong, there is no set/get  summary to share this There is a general error in this case. Hope can help beginners </span>
<span style= "White-space:pre" ></span>-->
  <insert id= "insertselective" parametertype= "com.bky.model.b" >    insert INTO B (User_name,password) VALUES (#{ User_name,jdbctype=varchar},#{password,jdbctype=varchar})  </insert>    <update id= " Updatebyprimarykey "parametertype=" com.bky.model.b ">    update B    set user_name = #{user_name,jdbctype= VARCHAR},      PASSWORD = #{password,jdbctype=varchar}    where id = #{id,jdbctype=integer}  </update>    <select id= "GetAll" resultmap= "Baseresultmap" >  SELECT * from B  </select></mapper>





Questions about MyBatis There is no getter for property named ' User_name ' in ' Class Com.bky.model. Instance class '

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.