mybatis調(diào)用比工具慢 如何使用myBatis在數(shù)據(jù)庫中插入數(shù)據(jù)并返回主鍵?
如何使用myBatis在數(shù)據(jù)庫中插入數(shù)據(jù)并返回主鍵?那個返回值1并不是主鍵,而是插入數(shù)據(jù)庫的記錄的條數(shù)。主鍵是自動賦值在對象中的。比如對象User,屬性id為主鍵,name,ageUser user
如何使用myBatis在數(shù)據(jù)庫中插入數(shù)據(jù)并返回主鍵?
那個返回值1并不是主鍵,而是插入數(shù)據(jù)庫的記錄的條數(shù)。主鍵是自動賦值在對象中的。比如對象User,屬性id為主鍵,name,ageUser user = new User()user.setName("test")user.setAge(16)調(diào)用mybatis的insert(user);返回值是1,該條記錄的主鍵通過user.getId()即可獲取。
用Mybatis框架怎么調(diào)用MySQL的函數(shù)?
Mapper文件,如下:
<select id="getPY" parameterType="String"
resultType="String" >
select getPY("中國") from dual
</select>
FUNCTION `getPY`(in_string VARCHAR(65534)) -- mysql函數(shù)!
如何在Mybatis的xml文件調(diào)用java類的方法?
使用的是ognl表達(dá)式,struts招牌在mybatis的映射xml文件調(diào)用java類的方法:
1.SELECT * FROMEC_CORE_USERWHERE (user_name=#{userName} or mail =#{userName} or mobile_phone = "${@net.ytoec.framework.security.EncryptionDecryption@dSecret(userName)}") and user_password=#{userPassword}入上面代碼所示。此處應(yīng)注意,方法必須為靜態(tài)方法。
2.獲取類里面的常量:r.czmc="${@com.ytoxl.module.datahub.kernel.dataobject.EcSystemLog@THE_AUDIT}"3.判斷是否為null: