工具:mybatis+pgsql
详见:pgsql官方文档
含义:to_char 是把日期或数字转换为字符串
表结构:
create table user(
id varchar(32) not null default sys_guid(),
username varchar(25) not null,
birthday timestamp not null default now()
)
案例 – timestamp转成年月日的格式
dao层
List<User> list();
sql
<select id = "list" resultType = "com.test.dto.User">
select username,
to_char(birthday,'YYYY-mm-dd')
from user
</select>

本文介绍如何使用PgSQL的to_char函数将timestamp类型字段转换为指定格式的字符串,并在MyBatis中实现这一功能。通过具体的表结构和SQL语句案例,展示如何在DAO层进行操作。
8034

被折叠的 条评论
为什么被折叠?



