Koj ua li cas rau kev zam hauv Spring MVC ib puag ncig?
Koj ua li cas rau kev zam hauv Spring MVC ib puag ncig?

Video: Koj ua li cas rau kev zam hauv Spring MVC ib puag ncig?

Video: Koj ua li cas rau kev zam hauv Spring MVC ib puag ncig?
Video: Nco Txog Hmoob - Xf. Txawj Pes Vaj & Fishermen's Project (Live Session) [Lyric Video] 2024, Kaum ib hlis
Anonim

Rau lis kev zam hauv String MVC , peb tuaj yeem txhais ib txoj hauv kev hauv chav tswj hwm thiab siv cov lus piav qhia @ExceptionHandler rau nws. Caij nplooj ntoos hlav configuration yuav ntes no annotation thiab sau npe rau txoj kev raws li kev zam handler rau kev sib cav kev zam chav kawm thiab nws cov subclasses.

Ntxiv rau qhov no, kev zam li cas rau lub caij nplooj ntoos hlav?

Caij nplooj ntoos hlav MVC Framework muab cov hauv qab no los pab peb ua kom muaj zog zam tuav . Controller Based - Peb tuaj yeem txhais kev zam handler txoj kev hauv peb cov chav kawm tswj. Yog li yog tias peb tau txhais ib qho ntawm cov no rau Kev zam class, ces tag nrho cov kev zam pov los ntawm peb qhov kev thov handler txoj kev yuav muaj tuav.

Ib yam li ntawd, chav kawm tshwj xeeb twg muaj feem cuam tshuam rau txhua qhov kev zam uas tau muab pov rau hauv Spring applications? Tag nrho cov kev zam pov tseg los ntawm Caij nplooj ntoos hlav JDBC Framework yog subclasses ntawm DataAccessException uas yog ib hom RuntimeException, yog li koj tsis tas yuav lis nws meej. Txhua yam kuaj kev zam thaum pov yuav raug mapped rau ib qho ntawm cov subclasses ntawm DataAccessException los ntawm lub moj khaum.

Hauv qhov no, muaj pes tsawg txoj hauv kev uas peb tuaj yeem daws qhov kev zam rau lub caij nplooj ntoo hlav?

Caij nplooj ntoos hlav muab ob txoj hauv kev rau tuav cov no kev zam : Siv XML configuration: qhov no zoo ib yam li zam tuav hauv Servlet/JSP, tshaj tawm ib SimpleMappingExceptionResolverbean hauv Caij nplooj ntoos hlav daim ntawv thov cov ntsiab lus cov ntaub ntawv thiab daim ntawv qhia kev zam hom nrog saib npe.

@ResponseStatus yog dab tsi?

Hom lus piav qhia Teb Status Kos ib txoj hauv kev lossis kev zam hauv chav kawm nrog cov xwm txheej code() thiab laj thawj() uas yuav tsum tau xa rov qab. Txoj cai lij choj raug siv rau HTTP cov lus teb thaum tus neeg tuav txoj kev raug hu thiab overrides cov ntaub ntawv xwm txheej los ntawm lwm txoj kev, xws li ResponseEntity lossis "redirect:".

Pom zoo: