BAEL-4404 | Added code to use CharacterEncodingFilter

This commit is contained in:
Tarun Jain 2020-08-22 23:27:21 +05:30
parent efd1705136
commit 8febb192a3
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package com.baeldung.charencoding;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.CharacterEncodingFilter;
@SpringBootApplication
public class CharacterEncodingDemo {
public static void main(String[] args) {
SpringApplication.run(CharacterEncodingDemo.class, args);
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(filter);
registrationBean.addUrlPatterns("/*");
return registrationBean;
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.charencoding.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class CharEncodingCheckController {
@GetMapping("/ping")
public String ping() {
return "path";
}
}