1.首先说明开发场景
*就是对该json格式数据传输到后台
- 后台实体类
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;@Data
@TableName("interview_information")
public class InterviewInformationEntity {@TableIdprivate Long id;/*** 应聘人员姓名*/private String name;/*** 应聘人员年龄*/private Integer age;/*** 性别*/private Integer sex;/*** 身份证号码*/private String idCard;/*** 邮箱*/private String mailbox;/*** 简历网页地址*/private String vita;/*** 应聘次数*/private Integer numberJob;/*** 应聘结果(未应聘0,应聘通过1,应聘未通过2)*/private Byte ending;/*** 面试信息表的id(具体的面试结果评分)*/private Long InterviewResultsId;/*** 应聘岗位*/private Long station;/*** 应聘时间*/private Data time;}
- controller中的代码
@RestController
@RequestMapping("/interview")
public class InterviewInformationController extends AbstractController {/*** 应聘人员信息service*/@AutowiredInterviewInformationService informationService;/*** 黑名单service*/@AutowiredInterviewBlacklistService blacklistService;/*** 将应聘人员基本信息存入数据库* @param interviewInformationEntity 应聘人员信息实体类* @return 存储是否成功*/@PostMapping("/setInterviewer")public R setInterviewer( @RequestBody InterviewInformationEntity interviewInformationEntity){//用户是否在黑名单中//获取黑名单List<InterviewBlacklistEntity> blacklistEntities=blacklistService.list(new QueryWrapper<InterviewBlacklistEntity>().eq("interview_static","true"));//用于查看是否获取到黑名单System.out.println("黑名单"+blacklistEntities);//存入黑名单idcardSet<String> blackList=new HashSet<>();blacklistEntities.stream().forEach(a -> {blackList.add(a.getIdCard());});//如果注册者的省份证号在黑名单中,直接报错if (blackList.contains(interviewInformationEntity.getIdCard())){return R.error("对不起,请另寻高就!");}//通过身份证查找是否存在在数据库中InterviewInformationEntity interview1=informationService.findByidCrid(interviewInformationEntity.getIdCard());boolean save;//判断查找的数据是否为空if (Objects.isNull(interview1)){//如果存入的数据未存在数据库中,则直接将用户信息注入到数据库save= informationService.saveOrUpdate(interviewInformationEntity);}else {//如果存入的数据不是空,则对数据库中的信息进行更新//将新存入的信息替换掉老信息存入到数据库中,通过id进行更新interviewInformationEntity.setId(interview1.getId());save = informationService.updateById(interviewInformationEntity);}return save?R.ok():R.error("保存失败");}}
- 报错数据
2024-04-30 09:07:35.474 INFO 25208 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/wedu] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-04-30 09:07:35.474 INFO 25208 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2024-04-30 09:07:35.484 INFO 25208 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 10 ms
2024-04-30 09:07:35.536 WARN 25208 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.wedu.modules.sys.entity.InterviewInformationEntity]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class lombok.Data (of type annotation) as a Bean
2024-04-30 09:07:35.537 WARN 25208 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.wedu.modules.sys.entity.InterviewInformationEntity]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class lombok.Data (of type annotation) as a Bean
2024-04-30 09:07:35.540 ERROR 25208 --- [nio-8080-exec-1] c.w.common.exception.RRExceptionHandler : Content type 'application/json;charset=UTF-8' not supportedorg.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supportedat org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:225)at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:158)at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131)at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:112)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at com.wedu.common.xss.XssFilter.doFilter(XssFilter.java:25)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:750)
2.解决
- 1.首先就是遇见了导包的博客,需要导下面的包,但是经过筛查并不缺
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.1.5.RELEASE</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.58</version></dependency><dependency><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-cbor</artifactId><version>2.9.9</version></dependency>
- 2.其次遇到了说请求头中缺少下面这个东西
ContentType :'application/json'
但是请求头中确实存在该东西
- 3.实体类中出现问题
- 该博客说其实这个问题的根本原因就是实体类中引用了一个没有实现实现Serializable 接口的对象,无法被反序列化,只需要在这个对象上添加@JsonIgnore这个注解即可。
- 并且该报错已经进行提示了
博客链接
2024-04-30 09:07:35.536 WARN 25208 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.wedu.modules.sys.entity.InterviewInformationEntity]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class lombok.Data (of type annotation) as a Bean
- 问题就在这
- 随后我将该数据加上@JsonIgnore注解,确实解决之前的问题了,
- 随后发现存入数据库时,数据类型不对等,然后反应 过来原来是数据类型错了,把时间日期类的Date写成Data,Data是lombok的类无法序列化