为什么自增字段id在增添数据时不填会报错填了数据库里又不一致

gongwenxian123 2017-02-17 03:14:43
/*ds_technician 的id是ds_technician_wallet的外键
*ds_technician_wallet里面增加数据时,不填id提示参数缺失如下
在浏览器网址处输入:http://localhost:8080/***/方法.do?tid=20&amount=100.2 这样会提示参数缺失,必须加上id,id随便赋值,但是在数据库里显示的id却是正常自增的数字,和输入的不一致
*/
<?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.sayesmed.doorservice.dao.DsTechnicianWalletDao">

<sql id="dsTechnicianWalletColumns">
a.id AS "id",
a.tid AS "tid",
a.amount AS "amount"
</sql>

<sql id="dsTechnicianWalletJoins">
</sql>

<sql id="dsTechnicianColumns">
b.id AS "id"
</sql>

<sql id="dsTechnicianJoin">
from ds_technician_wallet a, ds_technician b
where a.tid = b.id
</sql>

<select id="get" resultType="DsTechnicianWallet">
SELECT
<include refid="dsTechnicianWalletColumns"/>
FROM ds_technician_wallet a
<include refid="dsTechnicianWalletJoins"/>
WHERE a.id = #{id}
</select>

<select id="findList" resultType="DsTechnicianWallet">
SELECT
<include refid="dsTechnicianWalletColumns"/>
FROM ds_technician_wallet a
<include refid="dsTechnicianWalletJoins"/>
<where>

<if test="tid != null and tid != ''">
AND a.tid = #{tid}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
</otherwise>
</choose>
</select>

<select id="findAllList" resultType="DsTechnicianWallet">
SELECT
<include refid="dsTechnicianWalletColumns"/>
FROM ds_technician_wallet a
<include refid="dsTechnicianWalletJoins"/>
<where>

</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
</otherwise>
</choose>
</select>

<insert id="insert">
INSERT INTO ds_technician_wallet(
id,
tid,
amount
) VALUES (
#{id},
#{tid},
#{amount}
)
</insert>

<update id="update">
UPDATE ds_technician_wallet SET
tid = #{tid},
amount = #{amount}
WHERE id = #{id}
</update>

<update id="delete">
DELETE FROM ds_technician_wallet
WHERE id = #{id}
</update>

</mapper>
...全文
357 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fmaidou 2017-02-17
  • 打赏
  • 举报
回复
因为你这样写就必须给id传值,将 <insert id="insert"> INSERT INTO ds_technician_wallet( id, tid, amount ) VALUES ( #{id}, #{tid}, #{amount} ) </insert> 改为 <insert id="insert"> <selectKey keyProperty="id" resultType="int" order="BEFORE"> select 序列名.nextval from dual </selectKey> INSERT INTO ds_technician_wallet( id, tid, amount ) VALUES ( #{id}, #{tid}, #{amount} ) </insert> 如果是用的mysql,就改成 <selectKey keyProperty="id" resultType="int" order="BEFORE"> SELECT LAST_INSERT_ID() </selectKey>

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧