fasterxml

5.学习springmvc响应json数据

久未见 提交于 2020-04-06 08:46:17
一.配置不过滤静态资源文件:用来访问webapp中js,css,images文件 1.修改springmvc.xml 1 <!-- 配置前端控制器,用于设置哪些资源不拦截 --> 2 < mvc:resources location ="/css/" mapping ="/css/**" /> <!-- 样式 --> 3 < mvc:resources location ="/images/" mapping ="/images/**" /> <!-- 图片 --> 4 < mvc:resources location ="/js/" mapping ="/js/**" /> <!-- javascript --> 2.jsp: 1 <% @ page contentType = " text/html;charset=UTF-8 " language = " java " %> 2 3 < html > 4 < head > 5 < title > response </ title > 6 < script src ="js/jquery.min.js" ></ script > 7 < script > 8 // 页面加载,绑定点击事件 9 $( function () { 10 $( " #btn " ).click( function () { 11 alert( "

SSM+mybatis+c3p0+jsp常用整合注册分页插件pageHelper

耗尽温柔 提交于 2020-03-24 14:29:45
3 月,跳不动了?>>> 1.首先引入现骨干依赖,我们以spring5版本为例。 <dependencies> <!--springmvc引入依赖的包--> <!--springmvc--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.0.2.RELEASE</version> </dependency> <!--spring-jdbc--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.0.2.RELEASE</version> </dependency> <!--spring的单元测试--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.0.2.RELEASE</version> </dependency> <!--面向切面编程--> <dependency> <groupId>org.springframework<

spring swagger 2.9.2 For input string: ""粗暴解决

守給你的承諾、 提交于 2020-03-02 08:36:12
问题 最近从将springfox-swagger2 2.8.0升级到2.9.0版本,后台报如下错误: java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_181] at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_181] at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_181] at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181] at sun.reflect.NativeMethodAccessorImpl.invoke

0219 springmvc-拦截器和响应增强

旧街凉风 提交于 2020-02-26 17:36:08
拦截器 拦截器分同步拦截器和异步拦截器; HandlerInterceptor 方法和执行时机 可以看DispathcerServlet的原来确定它的三个方法的执行时机; AsynHandlerInterceptor 看注释,主要用来清理在并发环境加清理ThreadLocal的数据; ResponseBodyAdvice 对返回值备注了@ResponseBody或者返回ResponseEntity做了一些加工; 会在使用消息转换器转换为json数据之前进行数据转换输出; package com.springbootpractice.interceptor.config; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.springbootpractice.interceptor.config.interceptor.MyInterceptor; import lombok.SneakyThrows; import org.springframework.context.annotation.Configuration; import org.springframework.core

@JsonFormat与@DateTimeFormat注解的使用

不想你离开。 提交于 2020-02-26 00:28:53
从数据库获取时间传到前端进行展示的时候,我们有时候可能无法得到一个满意的时间格式的时间日期,在数据库中显示的是正确的时间格式,获取出来却变成了很丑的时间戳,@JsonFormat注解很好的解决了这个问题,我们通过使用@JsonFormat可以很好的解决:后台到前台时间格式保持一致的问题,其次,另一个问题是,我们在使用WEB服务的时,可能会需要用到,传入时间给后台,比如注册新用户需要填入出生日期等,这个时候前台传递给后台的时间格式同样是不一致的,而我们的与之对应的便有了另一个注解,@DataTimeFormat便很好的解决了这个问题,接下来记录一下具体的@JsonFormat与DateTimeFormat的使用过程。 声明:关于@JsonFormat的使用,一定要导入正确完整的包。 1.注解@JsonFormat 1.使用maven引入@JsonFormat所需要的jar包,我贴一下我这里的pom文件的依赖 <!--JsonFormat--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.8.8</version> </dependency> <dependency> <groupId>com

Jackson custom JsonSerializer - conditionally call default serializer

倾然丶 夕夏残阳落幕 提交于 2020-02-12 04:23:10
问题 What I want is to use default BeanSerializer conditionally for my class's objects: class MyCustomSerializer extends StdSerializer<AbstractEntity> { public MyCustomSerializer() { super(AbstractEntity.class); } @Override public void serialize(AbstractEntity o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { if (someCondition()) { serializeNormalWay(); //how? } else { //custom serialization } } } I've tried to do something like that: serializerProvider

spring rest dynamically exclude Object properties from serialization

时光总嘲笑我的痴心妄想 提交于 2020-01-30 08:39:26
问题 i want to exclude specific properties of spring rest response body. after hours of googling around i found this: http://www.jroller.com/RickHigh/entry/filtering_json_feeds_from_spring due to its date i like to ask if there is something more up-to-date for jackson and or fasterxml. JsonView doesnt fit my requirements as i need to have such case covered: if A is the set of all my attributes: one time i need to expose B with B ⊂ A. another time C with C ⊂ A. And B ∩ C != ∅ this would cause

spring rest dynamically exclude Object properties from serialization

耗尽温柔 提交于 2020-01-30 08:39:10
问题 i want to exclude specific properties of spring rest response body. after hours of googling around i found this: http://www.jroller.com/RickHigh/entry/filtering_json_feeds_from_spring due to its date i like to ask if there is something more up-to-date for jackson and or fasterxml. JsonView doesnt fit my requirements as i need to have such case covered: if A is the set of all my attributes: one time i need to expose B with B ⊂ A. another time C with C ⊂ A. And B ∩ C != ∅ this would cause

How to serialize a list of POJO using FasterXML library

痞子三分冷 提交于 2020-01-17 11:12:05
问题 I'm using FasterXML to serialize POJO. I want to serialize a list of my POJO. When serialize a signle POJO I get the expected xml (there's one problem --> question 2) Here's my code: List<Movie> movies = new ArrayList<>(); // add movies JacksonXmlModule module = new JacksonXmlModule(); module.setDefaultUseWrapper(false); xmlMapper = new XmlMapper(module); xmlMapper.disable(MapperFeature.AUTO_DETECT_CREATORS, MapperFeature.AUTO_DETECT_FIELDS, MapperFeature.AUTO_DETECT_GETTERS, MapperFeature

How to iterate through an Json array with same keys, but different values using Faster xml

半城伤御伤魂 提交于 2020-01-15 09:03:29
问题 I am trying to parse the json array with same key value which looks something like: Back End Response:"Countries":[{"state":"Queens Land "state":"Tasmania"}]. 2.I have created classes to read back end response and mapping the values with faster XML , but only the last value in the array is getting copied, instead of entire array. This is how I created my Data Transfer Object classes. Now the Test object contains Countries array, but only one of the State value is read. i.e "Countries":[