@Transactional不起作用解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sdaujsj1/article/details/89193398

@Transactional不起作用
解决方案:
把@Transactional 放在Service层就可以了 放在Controller层里不起作用。。。

这是Controller

@RequestMapping(value = {"save"})
    public String saveDiscover(OrientTeamsInfo orientTeamsInfo, RedirectAttributes redirectAttributes) {
        if (StringUtils.isNotEmpty(orientTeamsInfo.getPersonid())) {
            //主键不为空 进行修改操作
            //设置队长
            orientTeamsInfoService.setCaptain(orientTeamsInfo);
            addMessage(redirectAttributes, "修改成功");
            return "redirect:" + adminPath + "/flowmanage/update?teamsid="+orientTeamsInfo.getTeamsid();
        } else {
            return "redirect:" + adminPath + "/flowmanage/list";
        }
    }

这是Service 经典的java.lang.AritmeticExcption:/ by zero异常 嘿嘿

@Transactional
    public void setCaptain(OrientTeamsInfo orientTeamsInfo) {
        //1.把这个队伍的队长取消
        dao.cancelCaptain(orientTeamsInfo);
        //2.设置新的队长
        int i=2/0;
        dao.update(orientTeamsInfo);
    }

对应的xml也贴出来吧 显得专业

	<!--取消队伍的队长  1表示是队长-->
    <update id="cancelCaptain" parameterType="com.xwtec.flowmanage.entity.OrientTeamsInfo">
        update sdh5.T_ORIENT_PERSONINFO t
        set t.iscaptain=0
        where t.teamsid=#{teamsid} and t.iscaptain=1
    </update>
    
    <!--队员信息编辑-->
    <update id="update" parameterType="com.xwtec.flowmanage.entity.OrientTeamsInfo" >
        update sdh5.T_ORIENT_PERSONINFO
        <set >
            <if test="teamsid != null" >
                TEAMSID = #{teamsid,jdbcType=VARCHAR},
            </if>
            <if test="teamsname != null" >
                TEAMSNAME = #{teamsname,jdbcType=VARCHAR},
            </if>
            <if test="openid != null" >
                OPENID = #{openid,jdbcType=VARCHAR},
            </if>
            <if test="personname != null" >
                PERSONNAME = #{personname,jdbcType=VARCHAR},
            </if>
            <if test="iscaptain != null" >
                ISCAPTAIN = #{iscaptain,jdbcType=VARCHAR},
            </if>
            <if test="jointime != null" >
                JOINTIME = #{jointime,jdbcType=VARCHAR},
            </if>
            <if test="remark != null" >
                REMARK = #{remark,jdbcType=VARCHAR},
            </if>
        </set>
        where PERSONID = #{personid,jdbcType=VARCHAR}
    </update>

参考博客:
https://www.cnblogs.com/xiaohan666/p/9272581.html

猜你喜欢

转载自blog.csdn.net/sdaujsj1/article/details/89193398
今日推荐