@@ -19,18 +19,19 @@ categories:
1919 - 2.1.2. [ Gradle] ( #gradle )
2020 - 2.2. [ web.xml] ( #webxml )
2121 - 2.3. [ ApplicationContext.xml] ( #applicationcontextxml )
22- - 2.3.1. [ 全局异常处理] ( #全局异常处理 )
23- - 2.3.2. [ 自定义错误页面] ( #自定义错误页面 )
24- - 2.3.3. [ 中文编码问题] ( #中文编码问题 )
2522 - 2.4. [ 创建Controller] ( #创建controller )
2623- 3 . [ 使用] ( #使用 )
27- - 3.1. [ 配置类型转换] ( #配置类型转换 )
28- - 3.2. [ 拦截器] ( #拦截器 )
29- - 3.2.1. [ 拦截器机制] ( #拦截器机制 )
30- - 3.2.2. [ 自定义拦截器] ( #自定义拦截器 )
24+ - 3.1. [ 全局异常处理] ( #全局异常处理 )
25+ - 3.2. [ 自定义错误页面] ( #自定义错误页面 )
26+ - 3.3. [ 中文编码问题] ( #中文编码问题 )
27+ - 3.4. [ 配置类型转换] ( #配置类型转换 )
28+ - 3.5. [ 拦截器] ( #拦截器 )
29+ - 3.5.1. [ 拦截器机制] ( #拦截器机制 )
30+ - 3.5.2. [ 自定义拦截器] ( #自定义拦截器 )
31+ - 3.6. [ SSE] ( #sse )
3132- 4 . [ Tips] ( #tips )
3233
33- 💠 2024-03-30 11:43:28
34+ 💠 2024-12-25 22:37:44
3435****************************************
3536
3637# SpringMVC
@@ -172,7 +173,38 @@ categories:
172173 </bean >
173174 </beans >
174175```
175- ### 全局异常处理
176+
177+ ## 创建Controller
178+
179+ 包 com.test.controller 下创建一个类
180+ ``` java
181+ @RestController
182+ @RequestMapping (" /hi" )
183+ public class Hi {
184+ @RequestMapping (" /hi" )
185+ public String hi (){
186+ return " Hi" ;
187+ }
188+ }
189+ ```
190+ > 使用上 ResponseEntity 让响应结果规范
191+ ``` java
192+ @RequestMapping (" /handle" )
193+ public ResponseEntity<String > handle() {
194+ URI location = ... ;
195+ HttpHeaders responseHeaders = new HttpHeaders ();
196+ responseHeaders. setLocation(location);
197+ responseHeaders. set(" MyResponseHeader" , " MyValue" );
198+ return new ResponseEntity<String > (" Hello World" , responseHeaders, HttpStatus . CREATED );
199+ }
200+ ```
201+
202+ ************************
203+ # 使用
204+ > 在Springboot框架中,static templates 文件夹下分别代表了tomcat管理的静态文件和MVC负责跳转的HTML文件或JSP文件
205+ > 在static中对于路径的使用一定要带上应用路径,而在templates中就只要写相对路径即可
206+
207+ ## 全局异常处理
176208``` java
177209public class ExceptionHandler implements HandlerExceptionResolver {
178210 @Override
@@ -210,7 +242,7 @@ public class ExceptionHandler implements HandlerExceptionResolver {
210242> [参考博客](http: // www.cnblogs.com/exmyth/p/5601288.html)
211243> [ResponseBody 方案](https: // blog.csdn.net/xin917480852/article/details/78023911)
212244
213- ### 自定义错误页面
245+ ## 自定义错误页面
214246```java
215247 // 自定义错误页面 需要放在静态资源下面
216248 @Bean
@@ -223,7 +255,7 @@ public class ExceptionHandler implements HandlerExceptionResolver {
223255 });
224256 }
225257```
226- ### 中文编码问题
258+ ## 中文编码问题
227259> [参考博客](http: // www.cnblogs.com/dyllove98/p/3180158.html) `但是奇怪的是某些方法用第二种正常,有些还是要用第一种`
2282601. 单个方法:`@GetMapping (value = " /target/all" , produces = " application/json; charset=utf-8" )`
2292612. 或者整个应用 注意:`< / mvc: annotation- driven> ` 只能有一个,要将上面的覆盖掉
@@ -244,36 +276,6 @@ public class ExceptionHandler implements HandlerExceptionResolver {
244276 < / mvc: annotation- driven>
245277```
246278
247- ## 创建Controller
248-
249- 包 com. test. controller 下创建一个类
250- ```java
251- @RestController
252- @RequestMapping (" /hi" )
253- public class Hi {
254- @RequestMapping (" /hi" )
255- public String hi (){
256- return " Hi" ;
257- }
258- }
259- ```
260- > 使用上 ResponseEntity 让响应结果规范
261- ```java
262- @RequestMapping (" /handle" )
263- public ResponseEntity<String > handle() {
264- URI location = ... ;
265- HttpHeaders responseHeaders = new HttpHeaders ();
266- responseHeaders. setLocation(location);
267- responseHeaders. set(" MyResponseHeader" , " MyValue" );
268- return new ResponseEntity<String > (" Hello World" , responseHeaders, HttpStatus . CREATED );
269- }
270- ```
271-
272- ************************
273- # 使用
274- > 在Springboot 框架中,static templates 文件夹下分别代表了tomcat管理的静态文件和MVC 负责跳转的HTML 文件或JSP 文件
275- > 在static 中对于路径的使用一定要带上应用路径,而在templates中就只要写相对路径即可
276-
277279## 配置类型转换
278280
279281```xml
@@ -325,7 +327,9 @@ public class MythInterceptor extends HandlerInterceptorAdapter{
325327 }
326328}
327329```
330+
328331`配置MVC 的配置类`
332+
329333```java
330334@Configuration
331335public class WebMvcConfig extends WebMvcConfigurerAdapter {
@@ -344,6 +348,11 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter{
344348}
345349```
346350
351+ ## SSE
352+ TODO
353+
354+ ************************
355+
347356# Tips
348357> URL 中带了 jsessionid 参数,导致页面各种问题
349358- 一种原因:禁用cookie导致的
0 commit comments