Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
//
// }
}