jdbcTemplate fetches the TIMESTAMP date in the database

Be careful not to use jdbcTemplate to get the TIMESTAMP date in the database in this way, so that the returned date will be the current date, not the date queried in the database.

For example, the database field create_time is of type TIMESTAMP:

import java.util.Date;

String sql = "SELECT MAX(mtm.create_time) FROM t_message mtm";

Date result = jdbcTemplate.query(sql, paramMap, new BeanPropertyRowMapper<T>(Date.class));
// 上面那样写其实就相当于这样,无论数据库中是否能查询出结果
// Date result = new Date();

It should be changed to this:

String sDate = jdbcTemplate.query(sql, paramMap, new BeanPropertyRowMapper<T>(String.class));
Date result = DateUtil.parse(sDate);

For the specific reason, I tried to follow the code, but it felt too complicated to follow. . .

If you know the specific reason, please let me know.

Thanks!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325700199&siteId=291194637