@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime birthday;
[org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported]
出现这个415的错误,并不是请求头没有加application/json。 而是日期格式设置不对
跨时时区转化
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("GMT"));
System.out.println(zonedDateTime);
ZonedDateTime utcTime = zonedDateTime.withZoneSameInstant(ZoneId.of("GMT+8"));
System.out.println(utcTime);
spring 中使用代码提交事务
@Autowired
private PlatformTransactionManager platformTransactionManager;
@Override
public String createTeacherAndStudent() {
Teacher teacher = new Teacher();
teacher.setTeacherName("zhangsan02");
teacher.setTeacherNo(6l);
createTeacher(teacher);
Student student = new Student();
student.setBirthday(LocalDateTime.now());
student.setSage(20);
student.setSsex(1);
student.setSname("wangwu4");
createStudent(student);
return "SUCCESS";
}
private void createTeacher(Teacher teacher){
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
TransactionStatus transaction = platformTransactionManager.getTransaction(transactionDefinition);
teacherMapper.insert(teacher);
platformTransactionManager.commit(transaction);
}
private void createStudent(Student student){
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
TransactionStatus transaction = platformTransactionManager.getTransaction(transactionDefinition);
studentMapper.insert(student);
platformTransactionManager.rollback(transaction);
}