实体类
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date createTime;
mapper.xml
<select id="queryByTime" resultType="com.exam.demo.pojo.PaperInfo">
select create_time from exam
</select>
查询结果
自己得出了两种解决方案,可以解决这个问题
1.改掉实体类中的字段,使其与数据库中的字段保持一致(不怎么建议,大多数据库有关时间的字段都带有下划线)违反了驼峰命名规则
2.不使用select * 查询,在查不到值的字段后加上别名,例如:
<select id="queryByTime" resultType="com.exam.demo.pojo.PaperInfo">
select create_time as createTime from exam
</select>
`可以看到结果是可以查出具体时间,而不再显示null的问题
。。。。改了半天,发现前端还是get不到时间,一直为null
<span th:text="${paperInfo.getCreateTime()==null?1:2}"></span>
最后配置中开启驼峰命名转换才显示时间不为null
mybatis:
configuration:
map-underscore-to-camel-case: true