使用SpringMVC的@RequestBody后出现415错误

【C++】C++异常语法、使用、规范、异常安全及异常的优缺点 实际中我们可以可以去继承exception类实现自己的异常类。但是实际中很多公司像上面一样自己定义一套异常继承体系。因为C++标准库设计的不够好用。如果有一个块抛出一个异常,捕获异常的方法会使用 try 和 catch 关键字。try 块中放置可能抛出异常的代码,try 块中的代码被称为保护代码。C++ 提供了一系列标准的异常,定义在 中,我们可以在程序中使用这些标准的异常。异常是一种处理错误的方式, 阅读详情

昨天写程序,利用ajax向后台发送json对象请求的时候出现了415错误,网上的方法试了一大堆都不管用,后台我将springMVC的配置文件改成了前的,就可以了

springMVC更改之前

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd
                         ">

    <!-- 自动扫描  @Controller-->
    <context:component-scan base-package="com.mingtai.mavenweb">
      <!--  <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"></context:exclude-filter>-->
    </context:component-scan>

    <!--避免IE执行AJAX时,返回JSON出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>

    <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>application/json;charset=UTF-8</value>
            </list>
        </property>
    </bean>

    <bean id = "stringHttpMessageConverter" class = "org.springframework.http.converter.StringHttpMessageConverter"/>

    <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter"/> <!-- JSON转换器 -->
                <ref bean= "stringHttpMessageConverter" />
                <ref bean="jsonHttpMessageConverter" />
                <!--     <ref bean= "jsonHttpMessageConverter" />
                     <ref bean= "formHttpMessageConverter" />-->
            </list>
        </property>
    </bean>


    <!-- 配置视图解释器 jsp -->
   <!-- <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>-->
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/html/"/>
        <property name="suffix" value=".html"/>
        <property name="contentType" value="text/html"/>
    </bean>


    <!-- 文件上传配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 上传文件大小限制为31M,31*1024*1024 -->
        <property name="maxUploadSize" value="32505856"/>
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="4096"/>
    </bean>
</beans>

更改之后

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd
                             http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
                         ">

    <context:component-scan base-package="com.mingtai.mavenweb">
        <!--<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"></context:exclude-filter>-->
    </context:component-scan>
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes" value="application/json" />
                <property name="features">
                    <list>
                        <!--设置null值也要输出,fastjson默认是关闭的-->
                        <value>WriteMapNullValue</value>
                        <!--设置使用文本方式输出日期,fastjson默认是long-->
                        <value>WriteDateUseDateFormat</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/html/"/>
        <property name="suffix" value=".html"/>
        <property name="contentType" value="text/html"/>
    </bean>
</beans>

pom文件

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>mavenweb_parent</artifactId>
        <groupId>com.mavenweb</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../mavenweb_parent/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mavenweb_manage_web</artifactId>
    <packaging>war</packaging>

    <name>mavenweb_manage_web Maven Webapp</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.mavenweb</groupId>
            <artifactId>mavenweb_manage</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.miemiedev</groupId>
            <artifactId>mybatis-paginator</artifactId>
        </dependency>
        <!-- MySql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- 连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>

        <!-- 文件上传组件 -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        <!-- 缓存 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
        </dependency>


        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>

        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>

        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.1</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.1</version>
        </dependency>


      <!--
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.2</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.2</version>
        </dependency>-->
        <!--因为页面在web工程,所以,jstl要在这里,jstl是JSP的一个标签库-->
        <!-- JSTL标签类 -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>mavenweb_manage_web</finalName>

        <!--<pluginManagement>&lt;!&ndash; lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) &ndash;&gt;-->
            <!--<plugins>-->
                <!--<plugin>-->
                    <!--<artifactId>maven-clean-plugin</artifactId>-->
                    <!--<version>3.0.0</version>-->
                <!--</plugin>-->
                <!--&lt;!&ndash; see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging &ndash;&gt;-->
                <!--<plugin>-->
                    <!--<artifactId>maven-resources-plugin</artifactId>-->
                    <!--<version>3.0.2</version>-->
                <!--</plugin>-->
                <!--<plugin>-->
                    <!--<artifactId>maven-compiler-plugin</artifactId>-->
                    <!--<version>3.7.0</version>-->
                <!--</plugin>-->
                <!--<plugin>-->
                    <!--<artifactId>maven-surefire-plugin</artifactId>-->
                    <!--<version>2.20.1</version>-->
                <!--</plugin>-->
                <!--<plugin>-->
                    <!--<artifactId>maven-war-plugin</artifactId>-->
                    <!--<version>3.2.0</version>-->
                <!--</plugin>-->
                <!--<plugin>-->
                    <!--<artifactId>maven-install-plugin</artifactId>-->
                    <!--<version>2.5.2</version>-->
                <!--</plugin>-->
                <!--<plugin>-->
                    <!--<artifactId>maven-deploy-plugin</artifactId>-->
                    <!--<version>2.8.2</version>-->
                <!--</plugin>-->
            <!--</plugins>-->
        <!--</pluginManagement>-->


        <resources>
            <!--将java代码目录中的xml输出,默认不输出除resources目录外的xml文件-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>
</project>

controller方法

 @RequestMapping({"/customer/saveCustomer.do"})
    @ResponseBody
    public String saveCustomer(@RequestBody Customer customer) {
        System.out.println("id为++++++++++++++++" + customer.getCust_name());
        System.out.println("id为++++++++++++++++" + customer.getCust_id());
        if (customer.getCust_id() == null) {
            System.out.println("添加");
            this.customerService.addCustomer(customer);
        } else {
            System.out.println("修改");
            this.customerService.updateCustomer(customer);
        }

        return "VueCustomerList";
    }

这里有几个依赖很特别


 <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.1</version>
        </dependency>

又一次,我添加了下面这个jar包,竟然神奇的运行成功了,这时我将springMVC的配置文件改为以前的,看能不能运行成功,以此来判断是否是少了下面这个jar包的问题,结果失败,然后又改为了成功的那个springMVC配置文件,结果也不行了,然后,之后又把该jar包去掉,再运行,就又成功了。。。。一头雾水,到现在我都不知道怎么回事。。。

<dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.8.4</version>
    </dependency>

就这么神奇的好了,我自己都不知道哪里出了问题

补充:因该还是前台发送ajax请求时的问题,最近用公司的框架写东西,也出现了这个问题,首先排除了环境问题,因为公司的代码,也有用到这个的,但是完全没有问题,后台我调用了公司封装好的发送post请求的代码,就没有这个问题了。

错误的代码:

 Util.httpPost(this.api.page, query, function (result) {
                    app.showLoading = false;
                    if (result.success) {
                        app.submitList = result.data.rows;
                         app.pagination.total = result.data.total;
                    }
                });

正确的代码:

 Util.httpPostJson(this.api.submitOrCancel, app.archive, function (result) {
                if (result.success) {
                    if (status == 0) {
                        app.$message({message: '撤稿成功', type: 'success'});
                        app.getSubmitList();
                        console.log("执行加载函数");
                    }
                    if (status == 1) {
                        app.$message({message: '提交成功', type: 'success'});
                        app.getSubmitList();
                        console.log("执行加载函数");
                    }

httpPostJson的源码

 httpPostJson: function (url, data, callback) {
        axios.post(url, data)
            .then(function (response) {
                Util.checkHttpLogin(response, function (result) {
                    if (callback) callback(result, data);
                });
            })
            .catch(function (error) {
                console.log(error);
                if (callback) callback({success:false, message: "网络请求异常."}, data);
            });
    },

checkHttpLogin源码

//检查API请求是否需要登录,如果需要登录则跳转到重新登录页面,登录成功后刷新当前页面
    checkHttpLogin: function (response, callback) {
        if (browser.versions.mobile) {
            if (browser.versions.iPhone | browser.versions.android) {
                Util.checkHttpMobileLogin(response, callback);
            } else if (browser.versions.app) {
                // Util.checkHttpAppLogin(response, callback);
            }
        } else {
            Util.checkHttpPCLogin(response, callback);
        }
    }

推荐几个,比较好的在使用了@Request后出现415问题的帖子

链接1:https://blog.youkuaiyun.com/yixiaoping/article/details/45281721#comments
链接2:https://www.jianshu.com/p/a5ca1fc63f81
链接3:https://blog.youkuaiyun.com/kility/article/details/70144931
链接4:https://www.cnblogs.com/qq78292959/p/3761646.html

UE4 专用服务器搭建(UE4.27为例) 专用服务器、DS服务器 阅读详情

相关推荐

SAP公司间采购后台配置及前台操作详解

公司间采购后台配置及前台操作详解 SAP 实施中公司间交易几乎每个项目都会有此业务需求,比如内地很多公司都会在香港设置贸易型子公司。通过香港公司接单,然后转内地公司生产,或内地公司通过香港公司采购进口原材料,这些业务必然会涉及到公司间交易,下面我将详细说明下SAP是如何实现这种业务场景的,供大家参考。 配置前必须前台先创建公司间供应商主数据和客户主数据 1. 创建相应的客户主数据 功能说明 公司间...

weixin_40672823的博客 1万+

SpringMVC使用RequestBody注解之后出现415错误

百度上有很多人说是需要配置SpringMVC的json转换格式,我在写一个第三方支付接口的回调地址的时候用到了SpringMVC的RequestBody注解,自己用浏览器去测试然后会出现415错误,然后我就去配置SpringMVC发现怎么配都没有用,最后发现是用浏览地址栏测试的请求头中的Content-Type没有设置的原因,大家都知道ajax去访问带上RequestBody注解的方法之后,需要设...

minolk的博客 1309

每天一个优秀提示词学习收藏 - 文本创作篇(二)

宝子们,今天不藏私啦!我把这段时间四处搜罗、潜心钻研出来的文本创作 Prompt 提示词大礼包双手奉上,这可都是能让你的 AI 创作水平原地起飞的干货!走过路过不要错过,赶紧码住,开启你的 AI 创作进阶之旅吧!

2397

[SpringBoot填坑篇] 前端向后台传入实体类的对象@RequestBody出现请求415问题

没有RequestBody报400的错(用的是表单serialize方法,放到ajax的data中发送到后端),有RequestBody后又报415的错,解决办法如下: 转载文章:https://blog.youkuaiyun.com/java_xxxx/article/details/81163432

weixin_41887912的博客 870

别再为数据发愁了!盘点5个公开可用的医学图像数据集(含MRI/CT/PET合成任务)

本文详细介绍了5个高质量的公开医学图像数据集,涵盖MRI、CT和PET三大模态,适用于深度学习模型训练和医学图像合成任务。每个数据集均提供下载指南、预处理技巧和PyTorch加载示例,帮助研究人员快速获取和处理数据,解决医学AI开发中的数据瓶颈问题。

weixin_30689307的博客 523

搞懂 SAPUI5 Fiori 应用的 OData 授权维护:从 IWSG、IWSV 到 S_SERVICE 的完整实践

本文探讨了SAP Fiori项目中常见的授权问题及其解决方案。文章指出,开发人员常误将OData服务访问问题归咎于前端代码或配置,而实际上多因授权默认值未正确带入角色所致。详细分析了IWSG(前端服务组元数据)和IWSV(后端业务服务)两个关键对象的作用机制,强调应通过PFCG角色的Authorization Default入口维护服务对象,而非直接修改S_SERVICE授权对象。文章还提供了前后端授权配置的具体操作步骤,并特别提醒需同时配置前端和后端授权,才能确保应用完整可用性。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 205

SpringBoot踩坑(1)@RequestBody注解不能映射到实体类解决;

SpringBoot @Request注解不能映射到实体类

qq_52496741的博客 3176

手把手教你学Simulink--基于飞行控制与稳定性的场景实例:多旋翼无人机在风扰动下的稳定性分析

本文介绍了使用Simulink仿真多旋翼无人机在风扰动下稳定性的方法。通过构建包含飞行器动力学模型、PID控制系统和环境模拟模块的仿真系统,分析了无人机在不同风速条件下的飞行性能。详细说明了从创建模型、设置动力学方程、设计PID控制器到添加风扰动模型的完整流程,并提供了性能评估指标。该方法可用于验证控制系统有效性,优化飞行稳定性参数,为无人机控制系统的设计和调试提供参考。

MHD0815的博客 327

spring boot 中使用@requestBody问题

       今天使用spring boot 中@requestBody注解进行接受参数,出现异常,415 Unsupported Media Type,研究后发现,使用@requestBody注解的话, 前端传递参数时需要JSON格式的参数,而且Content-Type为:application/json;charset=UTF-8 格式,         另外如果@requestBody 和...

white_ice的博客 7350

电机驱动和电源等大电流设计中的并联 MOSFET设计

在电机驱动等应用中,半桥拓扑(通常为 3 相)用于生成在电机中产生正扭矩或负扭矩的交流电源信号。想要更高的输出电流能力,只有通过并联形成每个功能开关的 MOSFET,才能实现高输出电流。当多个功率 MOSFET 并联以增加系统整体电流能力容量时,通常假设电流在并联器件之间均等分配或均等共享。然而,在并联 MOSFET 时,需要考虑并联器件之间的电流分配。PCB 布局的若干特性和特定的MOSFET 参数会影响这种分配,并在参数不匹配或布局不对称时导致均流不平衡。

小幽余生不加糖 2485

2021.07.05【R语言】丨预测lncRNA并绘制venn图

目录摘要环境与方法依赖工具预测工具绘制工具使用命令预测lncRNA统计noncoding_ID绘制Venn图结果展示总结 摘要 接到一个单样品测lncRNA数据的项目,正好拿来练练手,梳理一下lncRNA流程。这里记录预测lncRNA并生成venn图的过程 环境与方法 R version 3.6.3 (2020-02-29) 依赖工具 预测工具 CPC2 CNCI Pfam CPAT 绘制工具 R:VennDiagram 使用命令 预测lncRNA CPC2 #更换env conda activate py

2035

SpringBoot Controller 中使用多个@RequestBody的正确姿势

最近遇到Controller中需要多个@RequestBody的情况,但是发现并不支持这种写法, 这样导致 1、单个字符串等包装类型都要写一个对象才可以用@RequestBody接收; 2、多个对象需要封装到一个对象里才可以用@RequestBody接收。 查阅StackOverFlow,受到一个解决方案的启发,本人改进为以下版本,并给出了详尽的注释,希望对大家有帮助。 改进后的方案支持...

悟鸣的技术博客 11万+

【图像超分】论文复现:经典超分 | SAN的Pytorch源码复现,跑通源码,适配高版本的python/pytorch/cuda,使用EDSR-PyTorch进行训练和测试

本文介绍了单幅图像超分辨率重建方法SAN(二阶注意网络)的代码实现。文章详细说明了在高版本Python/Pytorch环境下适配SAN源码的方法,并提供了修改后的完整代码和预训练模型下载链接。 主要亮点包括: 将SAN模型实现整合到EDSR-Pytorch框架中,解决了高版本环境下的兼容性问题 提供了完整的数据集准备指南(DIV2K训练集和5个测试集) 给出了详细的测试命令,涵盖x2、x3、x4不同放大倍率 公开了预训练模型和可视化结果的下载资源 提供了修改后的适配高版本环境的代码。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1412

springmvc后端通过@RequestBody将json数据封装出现415错误

springmvc后端通过@RequestBody将json数据封装出现415错误 错误 前端代码: $(document).ready(function () { $("#btn").click(function () { alert("访问Ajax"); // 发送ajax请求 $.ajax({ //编写json格...

博客——XiaoTang 782

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

SpringMVC使用@RequestBody浏览器报415错误

最近在写一个前后端分离项目,前后端数据交互都使用json的格式,在使用SpringMVC的@RequestBody时,一直报415的错误,意思就是后台无法处理content-type=application/json格式的数据,我后台已经使用@RequestBody,就是不行,但是如果参数类型为String就可以接收,实体类的就是不行,看了很多教程,冲浪了一天,终于找到了解决方案。 解决方式: 1。在项目中导入两个jar包 <dependency> <group

Mr_FenKuan的博客 1039

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

SpringMVC @RequestBody 自动转json Http415错误

项目中想用@RequestBody直接接收json串转成对象 网上查了使用方法,看着非常简单,不过经过测试很快发现页面直接报415错误。 经过一通查,多半的解决方法实说header里的 Content-Type 一定 application/json 但是问题依然没有解决。 最后在《Spring in Action》里找到一个信息 有两个前提条件:  The request’s Content-Type header must be set to application/json.  The Jacks

天天的专栏 6万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

springMVC中使用@RequestBody处理Ajax数据报415错误问题和常用状态码说明

springMVC中使用@RequestBody接收前台Ajax数据报415错误问题 博主遇到这个问题折腾了很久,网上找了好多资料,解决方法差不多都试过,还是一直报415错误,最后解决办法是换了jar版本。不知道什么原因,我一直用的是4.39版本的jar,最后换成4.0版本的jar成功解决了这个问题。可是我不觉得是jar版本问题,然后又换回4.39版本,又报415错误,再换回4.0版本,却没这个...

Bruce_Json的博客 868

java http 415错误_SpringMVC @RequestBody 自动转json Http415错误

转自: http://blog.youkuaiyun.com/tiantiandjava/article/details/46125141项目中想用@RequestBody直接接收json串转成对象网上查了使用方法,看着非常简单,不过经过测试很快发现页面直接报415错误。HTTPStatus415-typeStatusreportmessagedescriptionTheserverrefus...

weixin_34329963的博客 280

springmvc使用@requestBody注释json数据,浏览器错误415

其他的都不想说了,今天下午弄了好几个小时开始在网上搜索各种解决方案 po没有序列化,没有配置转换器,缺少Jackson包,ajax data有的说要字符串有的要对象什么奇奇怪怪的都有。 但是都试完了前端怎么都是415,后台总是打印一个警告 WARN 2016-11-09 00:23:23,265 [org.springframework.web.servlet.mvc.suppo

TheManOfCoding的博客 606

关于SpringMVC中使用@RequestBody注解用ajax传json出415错误的解释

这个问题我找了好久,也上网找了很多解决方案,都不敢用。 不明白为什么我的代码在我电脑上就415,发给别人,别人就正常运行。 今天终于明白了原因——版本的问题,包括jdk的版本也包括导入的jar包的版本 我电脑直接用的默认jdk——1.6的,用高版本的jar包会有错。换成低版本,比如 如果jdk版本为1.6的话,用这个版本的jar包运行,没有问题,不会有415的错误。 如果用的jdk版本为1.8的...

不言不扰 370

使用Springmvc @requestBody注解接收不到用实体类接收的json数据,http 415错误

servlet.xml文件中加入 <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 --> <context:annotation-config /> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.spri...

没有伞的孩子必须努力奔跑!—小林 2520

关于SpringMVC使用@RequestBody注解接受json格式数据报415错误

之前学习springMVC的时候,在使用@RequestBody接受json格式数据时页面报405错误,网上找了好多相关的资料,最终解决,原来是缺少了jackson的jar包。导入jackson相关的包就可以顺利获取到数据了。

每个人内心都有一团火,路过的人只看到了烟 3108

springmvc @requestbody引起的前端415 不支持媒体类型错误

前端代码: 提交json数据给控制器 &lt;form id="form"&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;年龄:&lt;/td&gt;&lt;td&gt;&lt;input name="age" id="age1"&gt;&lt;/td&gt;&lt

wang540498244的博客 3487

SpringMvc:在使用@RequestBody和@ResponseBody的时候报415错误

原因: 1、是没有导入Jackson的jar包 jackson-core-asl-1.9.11.jar jackson-mapper-asl-1.9.11.jar 2、springmvc的配置文件没有使用标签 在配置文件中配置

jzpkzm的专栏 514

java http 415错误_在SpringMVC中使用@RequestBody注解处理json时,报出HTTP Status 415的解决方案...

Spring的@RequestBody非常牛x,可以将提交的json直接转换成POJO对象。正好今天有这样的需求,使用一下,结果一直报415,十分头疼。HTTP 415 错误–不支持的媒体类型(Unsupported media type)我的angularJs是这样写的$http({method: "POST",url: url;headers: {'Content-type': 'appli...

weixin_35894622的博客 550

@RequestBody接收json对象报415的解决办法

前端请求: $.ajax({ url: basePath() + "/index/login.do", type : "post", data: JSON.stringify(form), dataType : "json", contentType : "applicati...

大造梦家的博客 6199
上一篇: SpringMVC发送请求的一个逻辑错误
下一篇: ElementUI中的Table和collapse实现checkbox的多选和取消选择
java_xxxx
博客等级 码龄9年 127粉丝 99原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值