package com.jc.spring.main;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.jc.bus.example.entity.ExampleEntity;
import com.jc.bus.example.serializer.ExampleSerializer;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages={"com.jc.bus.*.**"})
public class WebConfig extends WebMvcConfigurerAdapter{
@Bean
public ViewResolver viewresolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
@Bean
public MultipartResolver multipartResolver() throws IOException{
CommonsMultipartResolver cmr = new CommonsMultipartResolver();
cmr.setUploadTempDir(new FileSystemResource("/tmp/file"));
cmr.setMaxUploadSize(1048576);
cmr.setMaxInMemorySize(0);
return cmr;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(mappingJacksonHttpMessageConverter());
super.configureMessageConverters(converters);
}
@Bean
public JacksonAnnotationIntrospector jacksonAnnotationIntrospector() {
return new JacksonAnnotationIntrospector();
}
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
mapper.setAnnotationIntrospector(jacksonAnnotationIntrospector());
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
Map<String,Object> map = new HashMap<String, Object>();
ExampleSerializer exampleSerializer = new ExampleSerializer(ExampleEntity.class);
SimpleModule module = new SimpleModule("ExampleSerializer", new Version(2, 1, 1, "a", null, null));
module.addSerializer(ExampleEntity.class, exampleSerializer);
mapper.registerModule(module);
return mapper;
}
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter(){
RequestMappingHandlerAdapter amga = new RequestMappingHandlerAdapter();
List<HttpMessageConverter<?>> ls = new ArrayList<HttpMessageConverter<?>>();
ls.add(mappingJacksonHttpMessageConverter());
amga.setMessageConverters(ls);
return amga;
}
@Bean
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
messageConverter.setObjectMapper(objectMapper());
return messageConverter;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
// TODO Auto-generated method stub
configurer.enable();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
彻底根治Spring @ResponseBody JavaScript HTML特殊字符
共70个文件
class:14个
jar:13个
xml:10个
5星 · 超过95%的资源 需积分: 50 69 下载量 181 浏览量
2018-01-12
14:08:55
上传
评论 3
收藏 13.27MB ZIP 举报
温馨提示
Spring MVC下彻底解决@ResponseBody转义html特殊字符问题,解决包括尖角号(<>),单引号('),双引号("),按位与(&),反斜杠(\)。
资源推荐
资源详情
资源评论
收起资源包目录
springExample.zip (70个子文件)
spring
src
com
jc
bus
example
entity
ExampleEntity.java 443B
serializer
ExampleSerializer.java 1KB
service
web
ExampleController.java 1KB
spring
extend
HtmlFilter.java 1KB
UserMapper.java 700B
main
spring-transaction.xml 4KB
RootConfig.java 1KB
spring-datasource.xml 2KB
WebConfig.java 4KB
WebInit.java 1KB
SpringWebInitializer.java 664B
jdbc.properties 190B
.classpath 935B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.prefs.xml 305B
org.eclipse.wst.common.project.facet.core.xml 554B
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 650B
.jsdtscope 522B
org.eclipse.jdt.core.prefs 430B
org.eclipse.wst.validation.prefs 50B
pom.xml 3KB
target
classes
com
jc
bus
example
entity
ExampleEntity.class 822B
serializer
ExampleSerializer.class 2KB
service
web
ExampleController.class 2KB
spring
extend
HtmlFilter.class 2KB
UserMapper.class 870B
main
spring-transaction.xml 4KB
SpringWebInitializer.class 887B
spring-datasource.xml 2KB
RootConfig.class 1KB
WebConfig.class 6KB
WebInit.class 2KB
jdbc.properties 190B
maven-archiver
pom.properties 117B
generated-sources
annotations
test-classes
spring-0.0.1-SNAPSHOT
META-INF
MANIFEST.MF 39B
index.jsp 829B
WEB-INF
classes
com
jc
bus
example
web
ExampleController.class 1KB
spring
main
jdbc.properties 190B
spring-transaction.xml 3KB
SpringWebInitializer.class 887B
spring-datasource.xml 2KB
RootConfig.class 2KB
WebConfig.class 4KB
WebInit.class 2KB
lib
spring-core-4.3.14.BUILD-SNAPSHOT.jar 1.07MB
jackson-annotations-2.8.0.jar 54KB
spring-aop-4.3.14.BUILD-SNAPSHOT.jar 372KB
spring-beans-4.3.14.BUILD-SNAPSHOT.jar 745KB
spring-web-4.3.13.RELEASE.jar 806KB
commons-logging-1.2.jar 60KB
jackson-core-2.8.10.jar 276KB
spring-tx-4.3.13.RELEASE.jar 261KB
spring-expression-4.3.14.BUILD-SNAPSHOT.jar 258KB
jackson-databind-2.8.11.jar 1.19MB
spring-webmvc-4.3.13.RELEASE.jar 896KB
spring-jdbc-4.3.13.RELEASE.jar 418KB
spring-context-4.3.14.BUILD-SNAPSHOT.jar 1.09MB
maven-status
maven-compiler-plugin
compile
default-compile
inputFiles.lst 327B
createdFiles.lst 0B
m2e-jee
web-resources
META-INF
MANIFEST.MF 114B
maven
spring
spring
pom.properties 212B
pom.xml 3KB
spring-0.0.1-SNAPSHOT.war 6.62MB
.tern-project 66B
.project 2KB
WebRoot
META-INF
MANIFEST.MF 39B
index.jsp 829B
WEB-INF
classes
view
example.jsp 769B
lib
共 70 条
- 1
资源评论
- 潘敬2020-07-28不错的,很好用
- dalanldl2018-11-15感谢分享,虽然没有采用这种方案
aa80303857
- 粉丝: 43
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功