久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java - Mybatis插入mysql數(shù)據(jù)庫(kù)返回自增主鍵的問(wèn)題?

瀏覽:222日期:2024-04-01 13:32:51

問(wèn)題描述

在mapper.xml文件配置如下:

<mapper namespace='com.uiyllong.cims.dao.QuestMapper'> <resultMap type='com.uiyllong.cims.model.Selecter' id='resultSel'><id column='selp_id' property='selpId' /><result column='oid' jdbcType='INTEGER' property='oid' /><result column='content' jdbcType='VARCHAR' property='content' /><result column='selseq' jdbcType='INTEGER' property='selseq' /> </resultMap> <resultMap type='com.uiyllong.cims.model.Quest'><id column='qp_id' jdbcType='INTEGER' property='qpId' /><result column='q_content' jdbcType='VARCHAR' property='content' /><result column='qtype' jdbcType='INTEGER' property='qtype' /><result column='seq' jdbcType='INTEGER' property='seq' /><result column='s_oid' jdbcType='INTEGER' property='sOid' /><collection property='selecters' ofType='com.uiyllong.cims.model.Selecter' column='qseq_id' resultMap='resultSel'></collection> </resultMap>

<!-- 插入問(wèn)題 --> <insert parameterType='com.uiyllong.cims.model.Quest'useGeneratedKeys='true' keyProperty='qpId'>insert into quest_t<trim prefix='(' suffix=')' suffixOverrides=','> <if test='qpId != null'>qp_id, </if> <if test='content != null'>q_content, </if> <if test='qtype != null'>qtype, </if> <if test='seq != null'>seq, </if> <if test='sOid != null'>s_oid, </if></trim><trim prefix='values (' suffix=')' suffixOverrides=','> <if test='qpId != null'>#{qpId,jdbcType=INTEGER}, </if> <if test='content != null'>#{content,jdbcType=VARCHAR}, </if> <if test='qtype != null'>#{qtype,jdbcType=INTEGER}, </if> <if test='seq != null'>#{seq,jdbcType=INTEGER}, </if> <if test='sOid != null'>#{sOid,jdbcType=INTEGER}, </if></trim> </insert>

然后控制器調(diào)用后返回的居然一直是1 ,并沒(méi)有實(shí)現(xiàn)返回主鍵去網(wǎng)上找了一下 都是這樣加了兩個(gè)屬性而已useGeneratedKeys='true' keyProperty='qpId'

問(wèn)題解答

回答1:

你可能理解錯(cuò)了,mybatis返回主鍵并不是通過(guò)返回值的形式,而是通過(guò)set到實(shí)體的id上。你可以輸出Quest對(duì)象的qpId值,查看自增主鍵。

回答2:

那你數(shù)據(jù)庫(kù)對(duì)應(yīng)的表本身有沒(méi)有設(shè)置主鍵自增呢?或者支不支持?

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 邯郸县| 卢龙县| 桑日县| 江川县| 客服| 巴彦县| 临夏市| 囊谦县| 社会| 台湾省| 阳西县| 林口县| 尼玛县| 江山市| 汉川市| 曲周县| 林甸县| 启东市| 龙里县| 平安县| 巴林左旗| 南澳县| 沙坪坝区| 乃东县| 石渠县| 罗平县| 长宁县| 若尔盖县| 鄢陵县| 将乐县| 土默特左旗| 贞丰县| 扎兰屯市| 天水市| 库车县| 洞口县| 阜新市| 迭部县| 铁力市| 邵阳县| 沁水县|