SpringMVC第二篇【过滤编码器、注解开发、requestMapping、业务方法与传统参数】

OPNET仿真802.11 MAC源代码拆解:从DCF到CSMA/CA的工程实践 802.11 MAC协议是无线网络的核心,其DCF机制通过CSMA/CA和二进制指数退避实现信道共享。在OPNET仿真中,MAC层以进程模型和状态机驱动,源代码将载波侦听、退避计时、帧交换等逻辑拆解到函数级别。掌握这些代码,能帮助研究者验证自定义MAC改进算法,优化退避窗口和RTS阈值等参数,从而提升网络吞吐量并降低时延。本文深入拆解OPNET仿真802.11 MAC源代码,涵盖DCF实现、CSMA/CA退避逻辑及工程配置,为无线网络仿真提供可逐行修改的实践素材。 阅读详情

SpringMVC过滤编码器

在SpringMVC的控制器中,如果没有对编码进行任何的操作,那么获取到的中文数据是乱码!

这里写图片描述

即使我们在handle()方法中,使用request对象设置编码也不行!原因也非常简单,我们SpringMVC接收参数是通过控制器中的无参构造方法,再经过handle()方法的object对象来得到具体的参数类型的。

Struts2是使用拦截器来自动帮我们完成中文乱码的问题的。那么SpringMVC作为一个更加强大的框架,肯定也有对应的方法来帮我们完成中文乱码问题!

值得注意的是:该过滤编码器只能解决POST的乱码问题!

我们只需要在web.xml配置文件中设置过滤编码器就行了!


    <!-- 编码过滤器 -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

这里写图片描述


注解开发SpringMVC

我们在快速入门的例子中使用的是XML配置的方式来使用SpringMVC的,SpringMVC也能够支持注解。【个人非常喜欢注解的方式】

我们在使用Action的时候,要么继承着AbstractCommandController类,要么实现了Controller接口。当我们使用了注解以后就不用显示地继承或实现任何类了!

开发流程

使用@Controller这个注解,就表明这是一个SpringMVC的控制器!


@Controller
public  class HelloAction  {

}

当然了,现在Spring是不知道有这么一个注解的,因此我们需要在配置文件中配置扫描注解

值得注意的是:在配置扫描路径的时候,后面不要加.。。。不然扫描不了,我不知道学Struts2还是其他的地方时候,习惯加了.,于是就搞了很久!

   <!--扫描注解,后面不要加.*-->


    <context:component-scan base-package="zhongfucheng"/>

在控制器中写业务方法

@Controller
public class HelloAction {

    /**
     *
     * @RequestMapping 表示只要是/hello.action的请求,就交由该方法处理。当然了.action可以去掉
     * @param model 它和ModelAndView类似,它这个Model就是把数据封装到request对象中,我们就可以获取出来
     * @return 返回跳转的页面【真实路径,就不用配置视图解析器了】
     * @throws Exception
     */
    @RequestMapping(value="/hello.action")

    public String hello(Model model) throws Exception{
        System.out.println("HelloAction::hello()");
        model.addAttribute("message","你好");
        return "/index.jsp";
    }

}

跳转到index页面,首页得到对应的值。


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  这是我的首页 <br>
  ${message}
  </body>
</html>

这里写图片描述


当然了,基于注解和基于XML来开发SpringMVC,都是通过映射器、适配器和视图解析器的。 只是映射器、适配器略有不同。但是都是可以省略的!


    <!-- 基于注解的映射器(可选) -->
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>

    <!-- 基于注解的适配器(可选) -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

    <!-- 视图解析器(可选) -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>

更新:上边的适配器和映射器只是Spring3.1版本之前使用的、3.1版本之后现在一般用以下的两个


映射器:
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping


适配器:
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter

当然了,这上面两个配置也可以使用<mvc:annotation-driven>>替代注解处理器和适配器的配置。


RequestMapping

@RequestMapping能够控制请求路径和请求方式!

一个控制器写多个业务方法

到目前为止,我们都是一个控制器写一个业务方法,这肯定是不合理的。我们在Struts2中一个Action就对应多个业务方法了。那么我们在SpringMVC中又怎么写呢???

其实我们可以推理出来,@RequestMapping就是用于配置哪个请求对应哪个业务方法的!


public @interface RequestMapping {
    String[] value() default {};

    RequestMethod[] method() default {};

    String[] params() default {};

    String[] headers() default {};
}

当我们请求hello.action的时候,处理的业务方法是hello()…..当我们请求bye.action的时候,处理的业务方法是bye()


@Controller
public class HelloAction {

    /**
     *
     * @RequestMapping 表示只要是/hello.action的请求,就交由该方法处理。当然了.action可以去掉
     * @param model 它和ModelAndView类似,它这个Model就是把数据封装到request对象中,我们就可以获取出来
     * @return 返回跳转的页面【真实路径,就不用配置视图解析器了】
     * @throws Exception
     */
    @RequestMapping(value="/hello.action")
    public String hello(Model model) throws Exception{
        System.out.println("HelloAction::hello()");
        model.addAttribute("message","你好");
        return "/index.jsp";
    }
    @RequestMapping(value = "/bye.action")
    public String bye(Model model) throws Exception {
        model.addAttribute("message","再见");
        return "/index.jsp";
    }
}

这里写图片描述

分模块开发

当然了,我们在Struts2常常使用namespace来进行分模块开发,在SpringMVC中我们也可以这样干,并且我们又是使用的是@RequestMapping这个注解!

只要把@RequestMapping这个注解写到类上面去,就代表了分模块。



@Controller
//我们知道,如果是value属性上的注解,我们可以把value省略掉的
@RequestMapping("/zhongfucheng")
public class HelloAction {

    /**
     * @param model 它和ModelAndView类似,它这个Model就是把数据封装到request对象中,我们就可以获取出来
     * @return 返回跳转的页面【真实路径,就不用配置视图解析器了】
     * @throws Exception
     * @RequestMapping 表示只要是/hello.action的请求,就交由该方法处理。当然了.action可以去掉
     */
    @RequestMapping(value = "/hello.action")
    public String hello(Model model) throws Exception {
        System.out.println("HelloAction::hello()");
        model.addAttribute("message", "你好");
        return "/index.jsp";
    }

    @RequestMapping(value = "/bye.action")
    public String bye(Model model) throws Exception {
        model.addAttribute("message", "再见");
        return "/index.jsp";
    }
}

那么我们想要HelloAction该控制器处理我们的请求,访问的地址要么是:http://localhost:8080/zhongfucheng/hello.action,或者要么是http://localhost:8080/zhongfucheng/bye.action


限定某个业务控制方法,只允许GET或POST请求方式访问

我们如果想要限定某个业务控制方法,只允许GET或POST请求方式访问。还是通过@RequestMapping来实现。只要设定它的method属性就行了!


    @RequestMapping(value = "/bye.action",method = RequestMethod.POST)
    public String bye(Model model) throws Exception {
        model.addAttribute("message", "再见");
        return "/index.jsp";
    }

当我把业务方法的请求设置为POST以后,我想要通过GET方式来访问该业务方法。就行不通了!

这里写图片描述


业务方法写入传统web参数

我们的业务方法除了可以写Model这个参数以外,如果有需要我们还可以写request,response等传统Servlet的参数。这是一样可以使用的….

但是呢,我们并不建议使用传统的web参数,因为会耦合


@RequestMapping(method=RequestMethod.POST,value="/register")
    public String registerMethod(HttpServletRequest request,HttpServletResponse response) throws Exception{

        //获取用户名和薪水
        String username = request.getParameter("username");
        String salary = request.getParameter("salary");
        System.out.println("用户注册-->" + username + ":" + salary);

        //绑定到session域对象中
        request.getSession().setAttribute("username",username);
        request.getSession().setAttribute("salary",salary);

        //重定向/jsp/success.jsp页面
        //response.sendRedirect(request.getContextPath()+"/jsp/success.jsp");

        //转发/jsp/ok.jsp页面
        request.getRequestDispatcher("/jsp/ok.jsp").forward(request,response);

        //转发(提倡)
        return "/jsp/success.jsp";
    }

小细节:如果我们的返回值是返回一个真实路径,而我们在程序中又使用了转发或重定向。。。那么具体跳转的位置就是按我们程序中跳转的路径为准!


SAP MIGO屏幕增强的具体实施步骤介绍(SE19:MB_MIGO_BADI) <转载> 1.MIGO抬头屏幕增强具体增强实施步骤1.1.创建存储抬头客制化数据的增强表1.2.创建增强结构1.3.创建函数组ZMM_MIGO1.3.1.定义全局变量1.3.2.创建数据处理函数1.4.创建字屏幕9001屏幕PBOendif.endloop.1.5.实施新BADI增强SE19创建BADI实施双击实施类ZCL_MIGO_EN_01exportingendif.endmethod.endif.endif.exportingendmethod. 阅读详情

相关推荐

鸿蒙【ArkTS】使用TS装饰器封装网络请求HTTP

在HarmonyOS应用开发中,通过HTTP访问网络,可以使用官方提供的@ohos.net.http模块。但是官方提供的直接使用不太好使用,需要封装下才好。这里采用TS的装饰器实现AOP效果 完成前后端接口风格的统一

weixin_60376559的博客 5621

SpringMVC第二篇【过滤编码器、注解开发、requestMapping、业务方法与传统参数】...

SpringMVC过滤编码器 在SpringMVC的控制器中,如果没有对编码进行任何的操作,那么获取到的中文数据是乱码! 即使我们在handle()方法中,使用request对象设置编码也不行!原因也非常简单,我们SpringMVC接收参数是通过控制器中的无参构造方法,再经过handle()方法的object对象来得到具体的参数类型的。 Struts2是使用拦截器来自动帮我们完成中文乱...

3y 415

Python+Vue计算机毕业设计风电场监控系统的设计与实现7bd6i(程序+LW+源码+部署)

Python3.7.7+Django+Mysql5.7+pip list+HBuilderX(Vscode也行)+Vue+Pychram社区版。2. 前端:vue+css+javascript+jQuery+easyUI+highcharts。2.IDE环境:Python和Python 社区版都可以。Django + Vue +Python+Mysql 等等组成,B/S模式等等。该项目含有源码、文档、程序、数据库、配套开发软件、软件安装教程。1. 后端:Python、Vue、Django、Mysql。

华信计算机毕设源码程序 349

SSM学习----SpringMVC获取请求参数(二)

文章目录5.请求数据的乱码问题6.参数绑定注解7.获得Restful风格的参数8.自定义类型转换器9.获得Servlet相关的API10.获取请求头信息 5.请求数据的乱码问题 <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFi

红莲灭的博客 473

高通camx ThreadManager

m_pCore->AcceptNewJob是将一个Job或者任务插入一个Queue,有一个工作线程循环从Queue中取Job任务执行,执行任务就是回调任务中的callback函数,AcceptNewJob实现。调用AddToPriorityQueue将任务添加到queue任务队列,那么什么时候从这个queue中取任务执行呢?有个线程循环执行DoWork,最终调用checkAndDequeue取任务执行。

GetnextWindow的专栏 445

Ubuntu下Ollama局域网共享大模型服务:5分钟搞定配置与防火墙设置

本文提供了一份在Ubuntu系统上快速配置Ollama实现局域网共享大模型服务的实战指南。通过修改服务配置使其监听所有网络接口,并设置UFW防火墙规则,用户可在5分钟内让同一Wi-Fi下的其他设备(如笔记本、手机)便捷调用主机上的AI模型能力,实现团队或多设备间的AI资源共享。

ik6789012的博客 830

AJAX请求在使用@RequestMapping时返回中文乱码

博客来源:http://www.cnblogs.com/zique/p/6171862.html情况描述:使用SSM框架的项目,需要使用ajax请求并返回数据,但是设置所有服务器端和浏览器客户端的编码都同一为:UTF-8结果还是乱码。原因分析:(网上基本都是一致的答案)首先: 确定的是(经过多次测试的结果)只有当返回值是 String时才会出现中文乱码,而当返回值是Map<String, Objec

Phoenix_smf的博客 3616

2024广东省职业技能大赛云计算——集群部署GitLab

题目是这样的:在Kubernetes集群中新建命名空间gitlab-ci,将GitLab部署到该命名空间下,Deployment和Service名称均为gitlab,以NodePort方式将80端口对外暴露为30880,设置GitLab服务root用户的密码为admin@123,将项目包demo-2048.tar.gz导入到GitLab中并命名为demo-2048。GitLab是一个功能强大且灵活的 DevOps 平台,为开发团队和企业提供了从代码管理到持续集成、交付和部署的一整套解决方案。

kuuuugua的博客 4404

spring 源码分析 管理请求映射-上 (RequestMappingHandlerMapping)

RequestMappingHandlerMapping 类结构 继承结构: RequestMappingHandlerMapping impl实现 MatchableHandlerMapping接口、EmbeddedValueResolverAware接口 --|RequestMappingInfoHandlerMapping --|AbstractHandlerMeth...

Pazz 356

突破边缘AI算力瓶颈:YOLOv12模型剪枝与知识蒸馏联合优化全攻略

这套剪枝-蒸馏联合方案的优势在于其系统性和可靠性。它不是单一的技巧,而是一套完整的工程流程,确保了从研发到部署的无缝衔接。

m0_71589036的博客 221

把 SAP GUI 做成可维护的应用:Module Pool 基础与 Table Control 深入实战

SAP Module Pool 与 Table Control 开发要点 摘要:Module Pool 作为 SAP GUI 交互的核心技术,由程序、屏幕(Dynpro)和流逻辑(Flow Logic)组成,通过 PBO/PAI 事件驱动数据流。Table Control 是其中处理多行数据的核心控件,其开发关键在于: 正确理解 PBO/PAI 数据流机制 掌握 CXTAB_CONTROL 结构的关键属性(LINES、TOP_LINE 等) 合理设置列控制属性(CXTAB_COLUMN) 采用 LOOP W

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

设置编码格式

1.控制层利用注解设置编码格式: @RequestMapping(value="/aaa/bbb" ,produce="text/html;charset=utf-8")-----一般在返回字符串时使用; 返回对象时用UTF-8编码,返回字符串时用ISO-8859-1格式(手动转码) 2.设置响应编码: response.setContentType("text/html;charset=...

rlk512974883的博客 2912

在 SAP S/4HANA Public Cloud 中,用 RAP 一键生成 PDF 并在 Fiori 前端触发下载的完整方案

create;update;delete;// 生成并返回当前文档上下文。

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

springMVC框架下编码与解码(中文乱码)

编写项目中突然用到了中文,然后发生了一大堆的乱码,于是在百度上奋斗良久,终于解决了问题。 项目在java8环境下搭建,使用spring4.3.6 1)前端页面部分 &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;登录

trq1995的专栏 2897

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

SpringMVC学习笔记

一、SpringMVC 概述 1.1、概述 SpringMVC是基于Spring的一个框架,是Spring的一个模块,专门用来做web开发的,可以看做是Servlet的升级。 SpringMVC就是一个Spring容器,可以创建对象放入容器中,SpringMVC容器放的是@Controller控制器对象。 SpringMVC的优点: 轻量级:jar包很小。 使用简单:使用注解开发变得简单。 基于MVC架构:分工明确,各司其职。 1.2、SpringMVC入门程序 1.2.1、新建maven项目引入依

qq_53537846的博客 693

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

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

Spring MVC自定义类型转换器Converter、参数解析器HandlerMethodArgumentResolver

Spring MVC自定义类型转换器Converter、 Spring MVC自定义参数解析器HandlerMethodArgumentResolver(自定义注解、组合请求中的多个参数到一个JavaModel中)

健身变秃,coding变强 5347

深度学习工具包 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")

spring mvc自定义过滤器filter实现对请求参数编解码的代码

百度,google了半天即使再万能的stackoverflow上也没有得到解答,今天偶然间发现springmvc注解@RequestParam不是通过HttpServletRequest.java的getParameter(String name)方法得到的参数值,而是通过getParameterValues得到的,怪不得debug了半天getParameter方法就是未被调用,filter也没生

逸轩 1万+

spring 基于注解过滤器Filter设置,解决中文乱码

首先写一个Filter类,实现接口Filter import javax.servlet.*; import javax.servlet.annotation.WebFilter; import java.io.IOException; @WebFilter(filterName = "encodingFilter",urlPatterns = "/*") public class enc...

Martind的博客 1858

springmvc之编码问题(只看这一篇就足够了)

分析基于springboot 2.2.1,其他版本源码可能略有区别 编码问题 在编程中我们经常遇到中文乱码问题,主要分为以下几种: 返回一个页面 返回一个string类型且方法注释了@ResponseBody注解 返回一个json数据且方法注释了@ResponseBody注解 下面依次看看每种情况 1.1 返回页面乱码 这种情况在springboot中已经看不到了,因为springboot已经帮我们做了编码的自动配置为utf-8 首先看看正常页面编码是如何设置的: 在HttpEncodingAuto.

Haonan的博客 700

SpringMVC自定义消息转换器(Geometry序列化)

@ResponseBody、@RequestBody是我们开发中常用的注解,因为SpringMVC会扫描该类注解,选择适当的转换器进行数据转换。目前主流的是使用JSON格式数据,因此SpringMVC中有提供 MappingJackson2HttpMessageConverter 转换器,该转换器是我们最常用到的(网上有很多文章,都有进行过源码追踪,有兴趣的读者可以去了解下Spri...

shuoshuo132的博客 1942

注解@RequestMapping 的 produces属性

produces

weixin_45732391的博客 671

requestmapping设置响应形式和浏览器解析编码格式

text/html和text/plain的区别 1、text/html的意思是将文件的content-type设置为text/html的形式,浏览器在获取到这种文件时会自动调用html的解析器对文件进行相应的处理。 2、text/plain的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理。 @RequestMapping(value = "/ajaxStringData.do", method = RequestMethod.POST, produces

qq_36976201的博客 1745

SpringMVC-快速入门(二)-@RequestMapping详解

概述 @RequestMapping用于映射url到控制器类或一个特定的处理程序方法。可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。该注解共有8个属性。 @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Mapping public @interface RequestMapping { String name() defa

weixin_40017062的博客 2683

springmvc重定向中文路径问题编码踩坑

解决springmvc重定向redirect路径中有中文的问题

weixin_52755631的博客 414

@RequestMapping中produces

@RequestMapping中produces 一、produces 指定返回值类型,并且可以设置返回值类型和返回值的字符编码; @RestController @RequestMapping(value = "", produces = { "application/json;charset=UTF-8" }) @Api(value = "/", tags = { "UpFile" }) public class UpFileExtController { } demo: /**属性produce

jiangyyyeff的博客 1146

springboot 设置全局字符编码,解决乱码问题

设置http请求和相应的报文编码格式以 解决NO converter for [xxxx] with preset Content-Type ‘null‘的问题

XiXavier的博客 1万+
上一篇: SpringMVC第一篇【介绍、入门、工作流程、控制器】
下一篇: SpringMVC第三篇【收集参数、字符串转日期、结果重定向、返回JSON】
公众号Java3y
博客等级 码龄11年 447粉丝 225原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值