首页 > mysql读取语句错误

mysql读取语句错误

@Query("select a.id,a.title,a.author,a.guide,date_format(a.pulblicTime,'%y-%m-%d %T'),a.content from Articles a where a.id=:id")
Articles getOneAritcleById(@Param("id") Integer id); 

如上,我这样写,都不出来。我只是把对象A 拆开来,然后,再起其中的时间属性进行转换,但它说不行。

相对低,把上面这些属性写成a就没问题,可是这样写的话,那个时间属性就变成了一串数字了。

@Query("select a from Articles a where a.id=:id")

这是什么原因?


你查出来pulblicTime是一串数字,说明它的类型是long吧,这样的话date_format这个方法肯定是不能用的,它接受的是date类型。如果你想把long转成date,可以用from_unixtime方法。

【热门文章】
【热门文章】