SpringMVC 支持JSONP

SpringMVC 4 1使用ResponseBodyAdvice支持jsonp 阅读详情

springMVC 支持JSON网上有很多教程,但是对于JSONP的支持,网上有很多误导的地方,所以我写这个记录一下,方便后续查询。


首先写一个JSON advice:

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;

@ControllerAdvice
public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {
    public JsonpAdvice() {
        super("callback");
    }
}

然后在controller的RequestMapping上加上 produces=MediaType.APPLICATION_JSON_VALUE表示该http接口支持jsonP即可


@RequestMapping(value = "category/queryRoot", produces = MediaType.APPLICATION_JSON_VALUE)

Blender.粒子效果 Blender.粒子效果 ✦ shift+A新建一个棱角球,细分(之后要分解成许多小颗粒) ✦ 给球添加粒子系统,这时播放粒子会向下掉,力场权重☛重力☛0后,粒子会在球体周围运动 ✦ shift+A添加一个力场,调整力场强度 ✦如果粒子运动太快,我们可以在输出属性中调整时间重映射的原始值 ✦想让粒子在球周围运动而不是发散出去,在物理属性找到力场设置,调整流的大小 ✦S键将球形缩小到看不见 ✦给粒子变添加立方体的形状,在粒子属性里找到渲染选项,将“光晕”改为“物体”,在实例物体中选择新建的立方 阅读详情

相关推荐

数字IC后端设计实现 | PR工具中到底应该如何控制density和congestion?(ICC2&Innovus)

数字IC后端设计实现中到底应该如何控制cell density和congestion?(ICC2和Innovus两种解决方案)

weixin_37584728的博客 7136

springMVC实现jsonp

 jsonp原理js 是可以访问跨域资源的(通过ajax异步请求,或者通过src标签),但是浏览器对js的跨域做了限制,通过jsonp原理跳出浏览器限制,在页面中定义一个回调函数,来获取到资源.springMvc4.1之后:①@ControllerAdvice加上这个注解②实现AbstractJsonpResponseBodyAdvice如下:springMvc4.1之前:方法:继承原来的消息处理...

qq_41531324的博客 604

单细胞数据分析必备:Rdata、rds和qs格式到底怎么选?实测对比告诉你答案

本文深入对比了单细胞数据分析中常用的Rdata、rds和qs三种数据存储格式的性能差异,通过实测20GB单细胞转录组数据集,揭示了各格式在写入速度、压缩率和内存消耗等方面的优劣,并提供了针对不同场景的选型建议和性能优化技巧,帮助研究者提升大数据处理效率。

weixin_33686714的博客 486

Spring mvc 实现jsonp和json数据类型

在使用springmvc开发rest接口的时候很方便,可以直接使用@ResponseBody注解,直接加在springmvc的控制器类的方法上,springmvc会直接为我们将返回的对象序列化成为json类型的数据, 但是有时候有的接口调用方需要我们直接返回jsonp类型的数据,这时候可能就会需要我们自己修改代码,比如获取请求参数callback属性,手动序列化返回的对象,然后用...

weixin_30639719的博客 131

保姆级避坑指南:在Ubuntu 18.04上搞定速腾Helios雷达驱动与fast-LIO2的完整配置流程

本文提供了一份详细的速腾Helios雷达与fast-LIO2在Ubuntu 18.04上的配置避坑指南,涵盖驱动安装、数据格式转换到建图全流程。特别针对常见编译错误和数据转换问题提供了解决方案,帮助开发者高效完成环境搭建与建图任务。

weixin_27252001的博客 118

保姆级教程:在RK3588开发板上配置USB-C PD充电(基于HUSB311芯片与DTS详解)

本文详细介绍了在RK3588开发板上配置USB-C PD充电的完整流程,重点解析了HUSB311芯片的硬件原理与DTS安全配置。通过实战案例和调试技巧,帮助开发者避免常见错误,实现稳定可靠的Type-C PD快充功能,适用于从基础开发板到工业设备的多场景需求。

weixin_42552315的博客 526

SpringMVC中JSONP的基本使用

在第一次写博文的时候,写的是JSONP的基本实现原理,因为是第一次写可能有些不足。这一篇博文是简单的介绍在SpringMVC中JSONP的基本使用。(要是有不足,请各位指出,(~ ̄▽ ̄)~),

LinHenk 5737

dToF直方图之美_deadtime死区时间

IMX459的死区时间可以在6ns,这个时间是什么级别,车载激光雷达激光器的光脉宽一般都在4ns以上,也就是这个时间贴近去SPAD的死区时间,这就导致了pile up会非常弱,不会有太多数量的光子计数堆积,加上某些SPAD设计,对TDC有一些更深入的考量,所以不需要去校正pile up算法。Sensor层面决定了pile up的复杂程度,如果一个dToF的SPAD一致性非常好,那么pile up校正可以简单到极致,也就是一句代码的事,比如IMX611,优秀到不需要后端去考虑校正pile up。

dream it possible 1453

SpringMVC JSONP配置

前言 关于JSONP的配置有很多文章都讲过,也有很多实现方案。但本文依然存在的目的是规范JSONP。但为什么要规范? 本文基于的spring版本为5.1.7,在很多配置上会与5之前的版本有很大的区别。 为什么要规范JSONP 在springMVC 5的官方文档中,在CORS一章有说明不推荐使用JSONP。之所以推荐,就要先了解CORS,服务端最怕的就是恶意请求,其中有相当一部分是作为跨域请求过...

九丶弟 704

Openclaw错误分析与解决方案之:Agent couldn’t generate a response.

Openclaw错误分析与解决方案之:Agent couldn't generate a response. Note: some tool actions may have already been executed — please verify before retrying.

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 1330

QML从入门到实战 - 完整学习路线

想入门 QML 开发?来 “从零开始学 QML” 专栏,海量源码 + 实战案例 + 大型项目拆解,手把手教你搞定跨平台 UI 设计,小白也能轻松掌握!

BenBierBa的博客 3589

来说说SpringMVC + JSONP的跨域请求

先来说说场景,JSON,这货大家应该都懂,不懂的请自动面壁思过,那么什么是JSONP,不是JSON放了个P就叫JSONP,而是JSON with Padding,在进行跨域请求的时候需要的数据,什么是跨域,打个比方:在user.weixin.com下的某个页面下,用户服务需要调用订单服务,请求order.weixin.com,那么在这两个二级域名下,请求是互斥的,如果请求就会报错。   先来看...

weixin_34310127的博客 348

20、螺旋磁通压缩发生器:原理、性能与优化策略

本文详细介绍了螺旋磁通压缩发生器(HFCG)的结构、工作原理、性能指标和优化策略。HFCG是一种重要的爆炸脉冲功率装置,具有高电流和能量增益潜力,广泛应用于多个领域。文章从HFCG的基本组成出发,探讨了其运行特性、设计改进和理论模型,并提供了性能评估方法和功率调节策略,最后展望了其未来发展趋势。

t1u2v的博客 147

springmvc支持json和jsonp类型数据

在使用springmvc开发rest接口的时候很方便,可以直接使用@ResponseBody注解,直接加在springmvc的控制器类的方法上,springmvc会直接为我们将返回的对象序列化成为json类型的数据,

onefly 4730

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

SpringMVC中fastjson支持jsonp的实现

SpringMVC中fastjson支持jsonp的实现 前边一篇文章主要说了下前端处理jsonp的方式,这篇主要介绍了后台接收和响应jsonp的一种方式 继承fastjson消息转换器类:com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter package com.caiya.hongbao.we...

weixin_30808253的博客 131

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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

Springmvc实现对jsonp的支持

跨域问题 提到jsonp首先就要提一下跨域。因为只有遇到跨域问题才会使用jsonp。 现在的项目一般都是分布式项目,既然是分布式项目肯定就会涉及到跨域请求资源的问题,那么什么是跨域。 我们对资源的访问都是通过url,即域名+各种 参数。 当域名,端口号,协议不同时,即为跨域。 这种情况下就要使用jsonp来进行跨域请求。 jsonp的原理是利用src能跨域请求资源的特性来实现的,细心的...

shemuel的技术笔记 4938

springmvc 对 jsonp 的支持

在与前端开发人员合作过程中,经常遇到跨域名访问的问题,通常我们是通过jsonp调用方式来解决。jsop百科:http://baike.baidu.com/link?url=JKlwoETqx2uuKeoRwlk_y6HZ9FZxXTARLwm7QFOmuqex5p6-Ch5GQpSM5juf614F8hYaP2N3wDkU26slwvtnOa 如:请求 http://xxxx?&call...

weixin_30551947的博客 190

SpringMVC 4.1 新特性(一)JSONP的支持

为了启用@ResponseBody和ResponseEntity方法的JSONP支持,需声明一个@ControllerAdvice的bean,它扩展了AbstractJsonpResponseBodyAdvice,如下所示其中constructor参数指示JSONP查询参数名称: package com.somnus.advice; import org.springframework.

Franco的博客 781

springmvc支持jsonp

And an additional ControllerAdvice like this (see reference documentation): @ControllerAdvice public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice { public JsonpAdvice() {

z69183787的专栏 3627

SpringMvc 支持 jsonP

1、基于Controller 注解 Advice: @ControllerAdvice(annotations = RestController.class) public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice { public JsonpAdvice() { super("callback

z69183787的专栏 1227

springMVC支持jsonp

@RequestMapping("directives.json") @ResponseBody public MappingJacksonValue directives(String callback) { MappingJacksonValue mappingJacksonValue = new MappingJacksonValue("you can put everythi...

人生何处不相逢 241

springMVC中fastjson支持jsonp的实现

精选30+云产品,助力企业轻松上云!>>> 1、fa...

菜蚜的专栏 103
上一篇: java 读取字符串,截取空白, tab, 换行的新方法
下一篇: chrome插件开发入门
Viogs
博客等级 码龄15年 29粉丝 60原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址