Skip to content
UserService.java 1.5 KiB
Newer Older
hou's avatar
hou committed
package com.Service;

import com.Domain.Context;
import com.Domain.User;
import com.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * cglib 代理 Created by hcj on 18-7-16
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    // 脏读
    @Transactional(isolation = Isolation.READ_UNCOMMITTED)
    public void insert() {
        User user = new User();
        user.setUsername("hch");
        user.setPassword("123");
        user.setEnabled(true);
        Context build = Context.builder().username("hcj").password("123")
                .context("hello world").enabled(true).build();
        user.setContext(build);
        userMapper.insert(user);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        throw new RuntimeException();
    }

    // 不开启事务
//  @Transactional(readOnly = true)
    public List<User> findUser() {
        return userMapper.selectAll();
    }

//    public static void main(String[] args) {
//        User build = User.builder().username("hcj").password("123")
//                .context("hello world").enabled(true).build();
//        String s = JSONObject.toJSONString(build);
//        System.out.println(s);
//
//    }

}