Get请求报错406
com.imooc.reader.controllercom.imooc.reader.entity.Categorycom.imooc.reader.service.CategoryServicecom.imooc.reader.utils.ResponseUtilsorg.springframework.stereotype.org.springframework.web.bind.annotation.org.springframework.web.bind.annotation.org.springframework.web.bind.annotation.javax.annotation.java.util.List() CategoryController { CategoryService () ResponseUtils () { ResponseUtils resp = { List<Category> categories = .selectAll()resp = ResponseUtils().put(categories)} (Exception e) { e.printStackTrace()resp = ResponseUtils(e.getClass().getSimpleName()e.getMessage())} resp} }
问题描述:
测试报错406
相关截图:
相关代码:
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"> <context:component-scan base-package="com.imooc.reader"></context:component-scan> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=utf-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <mvc:default-servlet-handler/> <!--配置数据源(连接那个数据库)--> <bean id="dateSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/imooc_reader?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true"/> <property name="username" value="root"/> <property name="password" value="123456"/> <property name="initialSize" value="3"/> <property name="maxActive" value="10"/> </bean> <!--配置sessionFactory--> <!-- <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">--> <!-- 更改配置mybatis-plus初始化--> <bean id="sessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean"> <property name="dataSource" ref="dateSource"/> <property name="mapperLocations" value="classpath:mappers/*.xml"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> <!-- Mybatis-plus 3.4以后版本需要在MyBatisSqlSessionFactory屬性中進行設置--> <property name="plugins"> <array> <bean class="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor"> <property name="interceptors"> <list> <bean class="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor"/> </list> </property> </bean> </array> </property> </bean> <!--配置mapper扫描器--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.imooc.reader.mapper"/> </bean> <bean id="transactionManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dateSource"/> </bean> <tx:annotation-driven transaction-manager="transactionManger"/> </beans>
15
收起
正在回答
1回答
同学你好,
1、HTTP 406 错误指无法接受 (Not acceptable)错误。根据上述反馈代码(已乱码)老师这边无法准确查看,这里建议同学检查注解是否缺少
2、检查fastjson相关依赖是否正确引入,例如:
3、下载课程源码,对比各个类与xml文件的区别,将自己的代码替换至源代码中试着运行,看是否出现相同问题
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星