Create a new table
CREATE TABLEOrders (order_idINT PRIMARY KEYAuto_increment,order_noVARCHAR( -), Order_priceFLOAT);INSERT intoOrders (Order_no, Order_price)VALUES('AAAA', at);INSERT intoOrders (Order_no, Order_price)VALUES('bbbb', -);INSERT intoOrders (Order_no, Order_price)VALUES('CCCC', A);
and build a JavaBean.
Public class Order {privateint ID; Private String OrderNo; Private float Price ;}
Creating a mapping File
<id= "GetOrder" parametertype= "int" resulttype= "Order"> select * from Orders where Order_id=#{id}</Select >
This time because JavaBean inside the ID and the database inside the order_id does not correspond, after the execution is returned by the database to obtain the name of the field value, the bean does not have these field names, so the assignment failed.
There are two ways to resolve this:
Way one: By defining an alias in an SQL statement
<id= "Selectorder" parametertype= "int" resulttype = "_order" > Select order_id ID, order_no orderno,order_price price from orders where Order_id=#{id} </ Select >
Way two: Define a map
<SelectID= "GetOrder2"ParameterType= "int"Resultmap= "Getorder2map">SELECT * FROM Orders where Order_id=#{id}</Select> <Resultmaptype= "Order"ID= "Getorder2map"> <ID Property= "id"column= "order_id"/> <result Property= "OrderNo"column= "Order_no"/> <result Property= "Price"column= "Order_price"/></Resultmap>
MyBatis field names conflict with class property names