background

SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL SQL

XML code

<insert id="insertLogininfor" parameterType="SysLogininfor">
		<selectKey keyProperty="infoId" resultType="long" order="BEFORE">
			SELECT seq_sys_logininfor.NEXTVAL as infoId FROM DUAL
		</selectKey>
		insert into sys_logininfor (info_id, login_name, status, ipaddr, login_location, browser, os, msg, login_time)
		values (#{infoId}, #{loginName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate)
</insert>
Copy the code

Code interpretation

Use the incoming selectKey tag

<selectKey keyProperty="infoId" resultType="long" order="BEFORE">
			SELECT seq_sys_logininfor.NEXTVAL as infoId FROM DUAL
</selectKey>
Copy the code

Query the next value of sequence seq_sys_loginfor, assigned to infoId, of type Long, and order before other SQL operations

The infoId parameter is the same as the #{infoId} parameter