/** * Id自动加密的JSON序列化器 * 用于返回实体Long类型ID字段的自动序列化 */ public class IdEncryptSerializer extends JsonSerializer<Long> { /** * Method that can be called to ask implementation to serialize * values of type this serializer handles. * * @param value Value to serialize; can <b>not</b> be null. * @param gen Generator used to output resulting Json content * @param serializers Provider that can be used to get serializers for * serializing Objects value contains, if any. */ @Override public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException { if (Objects.isNull(value)) { gen.writeString(StringUtils.EMPTY); } else { gen.writeString(IdUtil.encrypt(value)); } } }
没明白这个序列化器的用意,Long类型不加密会怎样?
SpringBoot+Vue3+Element Plus 仿百度网盘实战
了解课程