自己学习用,待补充!
对比 LNC模块,就改一下 Controller (注解要换):
@Controller public class TccController { @Autowired ConsumerInfoMapper consumerInfoMapper; private static ConcurrentHashMap<String,String> maps = new ConcurrentHashMap<>(); @RequestMapping("/addConsumer-tcc") @Transactional(rollbackFor = Exception.class) @TccTransaction public @ResponseBody String AddConsumer(@RequestBody JSONObject json){ ConsumerInfo consumerInfo = new ConsumerInfo(); String id = (String) json.get("id"); System.out.println("获得Id : "+id); maps.put("id",id); consumerInfo.setId(id); consumerInfo.setName("li"); // int i = 1/0; consumerInfoMapper.insert(consumerInfo); return "addConsumer插入成功"; } public String confirmAddConsumer(@RequestBody JSONObject json){ System.out.println("Consumer--Producer :"+maps.get("id")); return ""; } public String cancelAddConsumer(@RequestBody JSONObject json){ String id = maps.get("id"); System.out.println("cancel-id : "+id); int i = consumerInfoMapper.deleteByPrimaryKey(id); System.out.println("cancel--Consumer : " +i); return ""; } }