@RestController
public class UserController {
@PostMapping("/user")
public Map addUser(LabUser labUser){
Map result = new HashMap<>();
result.put("success", true);
result.put("message", "新增成功!");
return result;
}
@GetMapping("/getUser")
public Map getUser(int id){
Map result = new HashMap<>();
result.put("success", true);
return result;
}
}
RechargeController 充值
@RestController
public class RechargeController {
@PostMapping("/addMoney")
public Map addMoney(int id, int addMoney){
Map result = new HashMap<>();
result.put("success", true);
result.put("message", "充值成功!");
return result;
}
}
ConsumeController消费
@RestController
public class ConsumeController {
@PostMapping("/buyGood")
public Map buyGood(int id, int useMoney, String goodName){
Map result = new HashMap<>();
result.put("success", true);
result.put("message", "消费成功!");
return result;
}
}
public class UserServiceTest {
private static UserService userService;
private static RestResult opResult = RestResult.create();
private static IUserDao userDao;
@BeforeClass
public void beforeTest() throws NoSuchFieldException, IllegalAccessException {
userDao = mock(IUserDao.class);
userService = new UserService();
ReflectionTddUtils.setFieldValue(userService, "userDao", userDao);
}
/**
* 创建用户测试
*/
@Test
public void addUser(){
LabUser labUser = new LabUser();
labUser.setUsername("张三");
labUser.setAge(12);
when(userDao.addUser(opResult, labUser)).thenReturn(1);
int update = userService.addUser(opResult, labUser);
assertThat(update, equalTo(1));
}
/**
* 查询用户测试
*/
@Test
public void getUser(){
LabUser labUserReturn = new LabUser();
labUserReturn.setId(1);
when(userDao.getUser(opResult, 1)).thenReturn(labUserReturn);
LabUser labUser = userService.getUser(opResult, 1);
assertThat(labUser.getId(), equalTo(1));
}
}
UserService产品代码编写
@Service
public class UserService implements IUserService {
@Autowired
private IUserDao userDao;
@Override
public int addUser(RestResult opResult, LabUser labUser) {
return userDao.addUser(opResult, labUser);
}
@Override
public LabUser getUser(RestResult opResult, int id) {
return userDao.getUser(opResult, id);
}
}
运行UserServiceTest
RechargeServiceTest充值测试代码
public class RechargeServiceTest {
private static IRechargeService rechargeService;
private static IRechargeDao rechargeDao;
private static RestResult opResult = RestResult.create();
@BeforeClass
public static void beforeTest() throws NoSuchFieldException, IllegalAccessException {
rechargeDao = mock(IRechargeDao.class);
rechargeService = new RechargeService();
ReflectionTddUtils.setFieldValue(rechargeService, "rechargeDao", rechargeDao);
}
@Test
public void addMoney(){
when(rechargeDao.addMoney(opResult, 1, 1000)).thenReturn(1);
int update = rechargeService.addMoney(opResult, 1, 1000);
assertThat(update, equalTo(1));
}
}
RechargeService充值产品代码
public class RechargeService implements IRechargeService {
@Autowired
private IRechargeDao rechargeDao;
@Override
public int addMoney(RestResult opResult, int id, int addMoney) {
return rechargeDao.addMoney(opResult, id, addMoney);
}
}
ConsumeServiceTest消费测试代码
public class ConsumeServiceTest {
private static IConsumeService consumeService;
private static IConsumeDao consumeDao;
private static RestResult restResult = RestResult.create();
@BeforeClass
public static void beforeClass() throws NoSuchFieldException, IllegalAccessException {
consumeService = new ConsumeService();
consumeDao = mock(IConsumeDao.class);
ReflectionTddUtils.setFieldValue(consumeService, "consumeDao", consumeDao);
}
@Test
public void test(){
when(consumeDao.buyGood(restResult, 1, 3000, "apple")).thenReturn(1);
int update = consumeService.buyGood(restResult, 1, 3000, "apple");
assertThat(update, equalTo(1));
}
}
ConsumeService消费产品代码
public class ConsumeService implements IConsumeService {
@Autowired
private IConsumeDao consumeDao;
@Override
public int buyGood(RestResult opResult, int id, int useMoney, String goodName) {
return consumeDao.buyGood(opResult, id, useMoney, goodName);
}
}
系统中统计数据,由于调用统计过程,执行时间超过了weblogic设置的时间,提示如下错误:
统计数据出错!
原因:The transaction is no longer active - status: 'Rolling Back. [Reason=weblogic.transaction.internal
Totally five patchs committed to erlang otp, just small patchs.
IMO, erlang really is a interesting programming language, I really like its concurrency feature.
but the functional programming style
两个步骤:
1.用w命令找到要踢出的用户,比如下面:
[root@localhost ~]# w
18:16:55 up 39 days, 8:27, 3 users, load average: 0.03, 0.03, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
package edu.xidian.graph;
class MyStack {
private final int SIZE = 20;
private int[] st;
private int top;
public MyStack() {
st = new int[SIZE];
top = -1;
}
public void push(i