Spring Boot设置编码方式

1,修改application.yml

spring:
   application:
      name: administrative-division-crawler
   http:
      encoding:
         charset: UTF-8
         enabled: true
         force: true

2,增加Config配置类

@Configuration
public class SpringWebConfig extends WebMvcConfigurationSupport {

    /** 请求url忽略大小写 */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        AntPathMatcher pathMatcher = new AntPathMatcher();
        pathMatcher.setCaseSensitive(false);
        configurer.setPathMatcher(pathMatcher);
    }
    
    /** utf-8编码 */
    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        return new StringHttpMessageConverter(Charset.forName("UTF-8"));
    }
    
    /** 关键代码 */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(responseBodyConverter());
        // 加载默认转换器
        addDefaultHttpMessageConverters(converters);
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false);
    }
}

3,设置maven编码

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<!-- jdk版本 -->
				<source>1.8</source>
				<target>1.8</target>
				<!-- 编码方式 -->
				<encoding>UTF-8</encoding>
			</configuration>
		</plugin>
	</plugins>
</build>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot Security 是 Spring Boot 官方提供的安全框架,基于 Spring Security 进行了封装和自动配置。它提供了一系列的安全功能,包括认证、授权和攻击防护等。使用 Spring Boot Security 可以快速地为 Web 应用程序添加安全特性,并且可以轻松地进行自定义配置。 下面是 Spring Boot Security 常用的功能: 1. 认证:Spring Boot Security 提供了多种认证方式,包括基于表单、HTTP Basic、HTTP Digest、OAuth2 等方式。可以根据需求选择不同的认证方式,并且可以自定义认证逻辑。 2. 授权:Spring Boot Security 提供了基于角色和基于权限的授权功能,可以通过注解或者编程方式来实现授权逻辑。 3. CSRF 防护:Spring Boot Security 自动为所有 POST、PUT、DELETE 请求生成 CSRF 令牌,并在表单提交时进行验证,防止跨站请求伪造攻击。 4. XSS 防护:Spring Boot Security 自动对所有输入参数进行 HTML 编码,防止 XSS 攻击。 5. Session 管理:Spring Boot Security 提供了多种 Session 管理方式,包括基于 Cookie、Redis、MongoDB 等方式。可以根据需求选择不同的 Session 管理方式,并且可以自定义 Session 管理逻辑。 6. 监控和审计:Spring Boot Security 提供了多种监控和审计功能,包括登录失败次数限制、登录日志记录、会话过期处理等。可以根据需求选择不同的监控和审计功能。 使用 Spring Boot Security 可以大大简化 Web 应用程序的安全性开发,提高开发效率和安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值