IPageRole page = roleMapperselectPagenew PageflowIngetPageNo flowIngetPageSize queryWrapper; return new PageableInfo pagegetRecordsstreammapr - mapperFacademapr RoleListI
可以使用MapStruct的@Mapping注解来定义转换规则,将Date类型的updatedAt字段转换为String类型的对应时间。具体实现如下:
首先,在mapper类中定义转换规则:
@Mapper
public interface RoleMapper {
// 定义转换规则
@Mappings({
@Mapping(source = "updatedAt", target = "updatedAt", dateFormat = "yyyy-MM-dd HH:mm:ss")
})
RoleListItem map(Role role);
// 其他方法...
}
然后在调用selectPage方法时,使用lambda表达式将Role对象转换为RoleListItem对象:
Page<Role> page = roleMapper.selectPage(new Page<>(flowIn.getPageNo(), flowIn.getPageSize()), queryWrapper);
return new PageableInfo<>(
page.getRecords().stream().map(r -> roleMapper.map(r)).collect(Collectors.toList()),
page.getTotal(),
page.getPages()
);
这样就可以将Date类型的updatedAt字段转换为String类型的对应时间了
原文地址: https://www.cveoy.top/t/topic/gg3O 著作权归作者所有。请勿转载和采集!