提交 632d5ea1 编写于 作者: yubinCloud's avatar yubinCloud

6-10 通过 JacksonConfig 配置 json 序列化时将 Long 型的 id 转换成 String 类型,以防止雪花算法生成的Long型...

6-10 通过 JacksonConfig 配置 json 序列化时将 Long 型的 id 转换成 String 类型,以防止雪花算法生成的Long型 id 在被前端 TypeScript 接收时number类型无法精确表示Long的问题
上级 7252966b
package io.github.yubincloud.fairywiki.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
@Configuration
public class JacksonConfig {
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder)
{
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
// 全局配置序列化返回 JSON 处理
SimpleModule simpleModule = new SimpleModule();
//JSON Long ==> String
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
return objectMapper;
}
}
......@@ -60,7 +60,7 @@ public class EbookService {
public void save(EbookSaveReqDto reqDto) {
Ebook ebookRecord = CopyUtil.copy(reqDto, Ebook.class);
if (ObjectUtils.isEmpty(ebookRecord.getId())) { // 判断 id 是否为空
// ebookRecord.setId(snowFlake.nextId());
ebookRecord.setId(snowFlake.nextId());
ebookMapper.insertSelective(ebookRecord);
} else {
ebookMapper.updateByPrimaryKey(ebookRecord);
......
......@@ -188,7 +188,7 @@ export default defineComponent({
/**
* 删除
*/
const handleDeleteEbook = (ebookId: any) => {
const handleDeleteEbook = (ebookId: string) => {
console.log(ebookId);
axios.delete("/ebook/delete/" + ebookId).then((response) => {
const respData = response.data;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册