9月19日 5点09分
public static void main(String[] args) {
try{
System.out.println(2/0);
} catch (Exception e){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(baos));
String exception = baos.toString();
System.out.println("baos:" + exception);
}
@RequestMapping(value = "/insert" , method = RequestMethod.POST)
public Object insert(@RequestBody Map<String,Object> map){
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = platformTransactionManager.getTransaction(definition);
try{
platformTransactionManager.commit(status);
return "添加成功";
}catch (Exception e){
//第二次插入报错后会被try catch捕获,捕获后执行rollback操作,第一条数据回滚
platformTransactionManager.rollback(status);
}
return "添加失败";
}
}