0
<insert id="insert" parameterType="com.youneverwalkalone.cent.web.model.Category" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
        LOCK TABLE t_category WRITE;

        UPDATE t_category SET rgt = rgt + 2 WHERE rgt greater than #{parentNode.lft,jdbcType=BIGINT};
        UPDATE t_category SET lft = lft + 2 WHERE lft greater than  #{parentNode.lft,jdbcType=BIGINT};

        insert into t_category (
        name, lft, rgt,
        time_created, people_created,
        state, type, project)
        values (
        #{record.name,jdbcType=VARCHAR}, #{parentNode.lft,jdbcType=BIGINT}+1, #{parentNode.lft,jdbcType=BIGINT}+2,
        #{record.timeCreated,jdbcType=TIMESTAMP}, #{record.peopleCreated,jdbcType=BIGINT},
        #{record.state,jdbcType=SMALLINT},#{record.type,jdbcType=VARCHAR},#{record.project,jdbcType=VARCHAR});

        UNLOCK TABLES;
    </insert>

Above is my code snippet. Call this insert method will get errors. My question: 1) Does mybatis supourt these grammar--multiple sql in one method? 2) If not support, how to handle this case.

1

1 Answer 1

0

1/ it is actually not related to Mybatis, if JDBC supports it and used DB does (as well as the driver) then yes you can do that with Mybatis. As noticed by Gabriele Coletta the question MyBatis executing multiple sql statements in one go, is that possible? contains the answer.

As you will see, the syntax is different across database types (mysql, ms-sql, oracle)

2/ without object since answer to 1/ is yes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.