SpringBoot

SpringBoot

springboot JSON

springboot 默认json解析器使用的是jackson,如果jackson不满足使用,可以整合其它的json解析器
springboot 整合fastjson  
	第一种方法:
		1.引入 fastjson 依赖
			<dependency>
	            <groupId>com.alibaba</groupId>
	            <artifactId>fastjson</artifactId>
	            <version>1.2.15</version>
			</dependency>
		2.启动类继承  WebMvcConfigurerAdapter
		  覆盖方法  configureMessageConverters
			  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
			        super.configureMessageConverters(converters);
			        FastJsonHttpMessageConverter fastConverter = newFastJsonHttpMessageConverter();
			        FastJsonConfig fastJsonConfig = new FastJsonConfig();
			        fastJsonConfig.setSerializerFeatures(
			            SerializerFeature.PrettyFormat
			        );
			        fastConverter.setFastJsonConfig(fastJsonConfig);
			        converters.add(fastConverter);
			  }
	第二种方法:
		1.在App.java启动类中,注入Bean : HttpMessageConverters
			@Bean
		    public HttpMessageConverters fastJsonHttpMessageConverters() {
		       FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
		       FastJsonConfig fastJsonConfig = new FastJsonConfig();
		       fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
		       fastConverter.setFastJsonConfig(fastJsonConfig);
		       HttpMessageConverter<?> converter = fastConverter;
		       return new HttpMessageConverters(converter);
		    }

HTML

在springboot中,默认静态资源位置是在resources下的static文件中,我们在resources文件下创建两个文件夹 templates 和 static  
static下面用来存放 JS 等静态资源    templates下面用来存放 html等静态界面
在springboot中使用html的一种方式 ,引入html相关依赖
	1.依赖
	    <dependency>  //需要关注标签闭合或者字符转义
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
	    <dependency>   //避免Thymeleaf对html语法检查过严  不用再去关注
           <groupId>net.sourceforge.nekohtml</groupId>
           <artifactId>nekohtml</artifactId>
        <version>1.9.22</version>
     </dependency>
	2.配置文件 application.properties
		//thymelea模板配置
		spring.thymeleaf.prefix=classpath:/templates/user/
		spring.thymeleaf.suffix=.html
		//避免Thymeleaf对html语法检查过严  不用再去关注
		spring.thymeleaf.mode=LEGACYHTML5
		spring.thymeleaf.encoding=UTF-8
		//热部署文件,页面不产生缓存,及时更新
		spring.thymeleaf.cache=false
		spring.resources.chain.strategy.content.enabled=true
		spring.resources.chain.strategy.content.paths=/**
	    // 静态文件请求匹配方式
		spring.mvc.static-path-pattern=/**
		// 修改默认的静态寻址资源目录
		spring.resources.static-locations=classpath:/templates/,classpath:/META-INF/resources/,\
		classpath:/resources/,classpath:/static/,classpath:/public/
	3.引入资源路径要使用 th:
		<script th:src="@{/js/user.js}"></script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值