| package com.wzy.bootmtp.test;

    import com.wzy.bootmtp.mapper.UserMapper;
    import com.wzy.bootmtp.pojo.User;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;

    import java.util.List;

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class TestSpringBoot {

    1. @Autowired<br /> **private **UserMapper **userMapper**;
    2. @Test<br /> **public void **test1(){<br /> //查询<br /> User user = **userMapper**.selectById(1L);
    3. //修改数据<br /> user.setName(**"啊哈哈"**);<br /> user.setEmail(**"hello@qq.com"**);
    4. //模拟取出数据后,数据库中version实际数据比取出的值大,即已被其它线程修改并更新了version<br /> user.setVersion(user.getVersion() + 1);<br /> <br /> //执行更新<br /> **userMapper**.updateById(user);<br /> }<br />}

    | | —- |

    日志显示,修改条数为0.
    image.png
    数据库中的数据并没发生改变,说明加锁成功。
    image.png