SpringMVC ?? ??
1, @Controller
SpringMVC?? Controller? DispatcherServlet? ??? ??? ???? ??? ?????. ???? ??? ???? ???? ?? Model? ??????. ???? ?? ??? ?? ??? ? ??? ?? ?? ???? ?????. SpringMVC? ????? ???? ?? ??? ??? ?????. ?? ???? ????? ?? ?????? ??? ??? ????. ???? ????? ???? ?? @Controller? ???? @? ?? ??? ???? ???. RequestMapping ? @RequestParam? ???? URL ??? ???? ???? ???? ???? ????? ???? ? ??? ???. ?? Controller? HttpServletRequest ? HttpServletResponse? ?? HttpServlet ??? ?? ???? ??? Controller? ??? ?? ??? ?? ???? ?? ? ????.
@Controller? ???? ???? ? ?????. ??? ???? SpringMVC ???? ?????. ???? ????? ??? ?? ???? ???? ???? ?? ???? @RequestMapping ??? ?? ??? ?????. @Controller? ???? ???? ??? ??? @RequestMapping??? ??? ?? ???? ??? ??? ???? ???????. ??? ???? @Controller ??? ???? ????? ??? SpringMVC? ???? ????? ?? ? ????. ???? ?? Spring? ?? ???? ??? ?????. ???? ?? ???? ?? Spring? ??? ?????? ?? ??? ?? ? ???? ???? Spring? ????? ???. ? ?? ??? ????.
(1) SpringMVC ?? ??? MyController? Bean ??? ?????.
(2) SpringMVC ?? ???? @Controller? ??? ????? ?? ? ?? ??? Spring? ?????.
<!--方式一--> <bean class="com.host.app.web.controller.MyController"/> <!--方式二--> < context:component-scan base-package = "com.host.app.web" />//路徑寫到controller的上一層(掃描包詳解見下面淺析)
2.@RequestMapping
RequestMapping? ?? ?? ??? ???? ? ???? ???? ???? ????? ??? ? ????. ????? ????? ?? ??? ???? ???? ?? ???? ? ??? ?? ??? ????? ?????.
RequestMapping ???? 6?? ??? ????. ????? ??? ?? ?? ? ?? ??? ????(?? ?? ??? ??).
1. ?, ???;
?: ??? ?? ??? ?????. ??? ??? URI ??? ??? ? ????(??? ???).
method: ??? ??? ??? ?????. , PUT, DELETE ?
2, Consumers, presents
consumes: application/json, text/html? ?? ?? ??? ?? ??? ??(Content-Type)? ?????.
produces: ???? ?????. ?? ??? ??? ???? ???? ??
3. params, headers
params: ??? ??? ? ?? ?? ???? ?? ???? ???. ? ???? ??? ? ????.
??: ? ???? ??? ????? ??? ??? ??? ?? ?? ?? ????? ???.
3. @Resource? @Autowired
@Resource? @Autowired? ?? Bean ??? ?????. ??? @Resource? Spring? ??? ????. ????? Spring? ? ??? ??? ?????.
1. ???
? ? ??? ?? ???? ??? ? ????. ? ? ??? ???? setter ???? ??? ??? ????.
2. ???
(1) @Autowired
@Autowired? Spring?? ???? ???? org.springframework.beans.factory.annotation.Autowired ???? ???? ?? byType? ???? ?????.
public class TestServiceImpl { // 下面兩種@Autowired只要使用一種即可 @Autowired private UserDao userDao; // 用于字段上 @Autowired public void setUserDao(UserDao userDao) { // 用于屬性的方法上 this.userDao = userDao; } }
@Autowired ??? ??(byType)? ?? ?? ??? ?????. ????? ?? ??? ??? ???. null ?? ???? ?? ?? ?? ??? false? ??? ? ????. ??(byName)?? ????? @Qualifier ??? ?? ??? ? ????.
public class TestServiceImpl { @Autowired @Qualifier("userDao") private UserDao userDao; }
(2) @Resource
@Resource? ????? J2EE?? ???? ByName? ?? ?? ???? javax.annotation.Resource ???? ???? ???. @Resource?? name? type??? ? ?? ??? ??? ??? Spring? @Resource ??? name ??? bean? ???? ???? type ??? bean? ???? ?????. ??? name ??? ???? byName ?? ?? ??? ????, type ??? ???? byType ?? ?? ??? ????. name?? type ??? ?? ???? ??? byName ?? ?? ??? ???? ????? ?? ?????.
public class TestServiceImpl { // 下面兩種@Resource只要使用一種即可 @Resource(name="userDao") private UserDao userDao; // 用于字段上 @Resource(name="userDao") public void setUserDao(UserDao userDao) { // 用于屬性的setter方法上 this.userDao = userDao; } }
??: @Resource? setter ???? ???? ?? ?? ????. ?? ?? ?? ??? ? ???? ??? ?? ???? ?? set ? get? ?? ??? ???? ?????.
@Resource ???? ??:
① ??? ??? ??? ???? ????? Spring ?????? ???? ?? ?????. ???? ??? ??? ?????.
② ??? ???? ?? ??(id)? ???? Bean? ???? ?????? ?????. ?? ? ??? ??? ?????.
3 ??? ???? ???? ?????? ???? ???? ?? Bean? ????? Bean? ?? ? ???? ??? ?????.
④如果既沒有指定name,又沒有指定type,則自動按照byName方式進行裝配;如果沒有匹配,則回退為一個原始類型進行匹配,如果匹配則自動裝配。
@Resource的作用相當于@Autowired,只不過@Autowired按照byType自動注入。
4、@ModelAttribute和 @SessionAttributes
代表的是:該Controller的所有方法在調(diào)用前,先執(zhí)行此@ModelAttribute方法,可用于注解和方法參數(shù)中,可以把這個@ModelAttribute特性,應(yīng)用在BaseController當中,所有的Controller繼承BaseController,即可實現(xiàn)在調(diào)用Controller時,先執(zhí)行@ModelAttribute方法。
@SessionAttributes即將值放到session作用域中,寫在class上面。
具體示例參見下面:使用 @ModelAttribute 和 @SessionAttributes 傳遞和保存數(shù)據(jù)
5、@PathVariable
用于將請求URL中的模板變量映射到功能處理方法的參數(shù)上,即取出uri模板中的變量作為參數(shù)。如:
@Controller public class TestController { @RequestMapping(value="/user/{userId}/roles/{roleId}",method = RequestMethod.GET) public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId){ System.out.println("User Id : " + userId); System.out.println("Role Id : " + roleId); return "hello"; } @RequestMapping(value="/product/{productId}",method = RequestMethod.GET) public String getProduct(@PathVariable("productId") String productId){ System.out.println("Product Id : " + productId); return "hello"; } @RequestMapping(value="/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET) public String getRegExp(@PathVariable("regexp1") String regexp1){ System.out.println("URI Part 1 : " + regexp1); return "hello"; } }
6、@requestParam
@requestParam主要用于在SpringMVC后臺控制層獲取參數(shù),類似一種是request.getParameter("name"),它有三個常用參數(shù):defaultValue = "0", required = false, value = "isApp";defaultValue 表示設(shè)置默認值,required 銅過boolean設(shè)置是否是必須要傳入的參數(shù),value 值表示接受的傳入的參數(shù)類型。
7、@ResponseBody
作用: 該注解用于將Controller的方法返回的對象,通過適當?shù)腍ttpMessageConverter轉(zhuǎn)換為指定格式后,寫入到Response對象的body數(shù)據(jù)區(qū)。
使用時機:返回的數(shù)據(jù)不是html標簽的頁面,而是其他某種格式的數(shù)據(jù)時(如json、xml等)使用;
8、@Component
相當于通用的注解,當不知道一些類歸到哪個層時使用,但是不建議。
9、@Repository
用于注解dao層,在daoImpl類上面注解。
?推薦教程:《Java教程》
? ??? SpringMVC ?? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

JDBC ????? ???? ????? ?? ?? ?? ??? ?? ?? ??? ?? ? ?? ??? ?? ?? ?? ??? ???????. 1. ????? ????? Conn.SetAutoCommit (False)?? ??????. 2. ??? ? ????? ?? ?? SQL ??? ?????. 3. ?? ??? ??? ?? Conn.commit ()?? ???? ??? ???? ???? ?? ??? ???? Conn.Rollback ()?? ??????. ???, ? ??? ???? ????, ??? ???? ????, ?? ??? ??? ?? ??? ??? ???? ? ???????. ?? ?? ?? ???? ????? ??? ???? ?? ?? ???? ???? ??? ????? ?? ??? ??? ? ?? ???? ?? ????.

?? ?? ? ?? ???? ???? ?? Java.Time ???? ???? ??????. 2. LocalDate, LocalDateTime ? LocalTime? ?? ?? ??? ??? ?????. 3. () ???? ???? ?? ??? ??? ????. 4. ???/???? ??? ???? ??? ????? ??? ??????. 5. ZonedDateTime ? Zoneid? ???? ???? ??????. 6. DateTimeFormatter? ?? ?? ? ?? ?? ?? ???; 7. ??? ?? ?? ?? ??? ????? ?? ??????. ?? Java? ?? ??? ???? ??? ??? ???? Java.Timeapi ??? ?? ??? ???????.

Pre-FormancetArtUptimeMoryUsage, Quarkusandmicronautleadduetocompile-timeprocessingandgraalvsupport, withquarkusoftenperforminglightbetterine serverless sinarios.2.thyvelopecosyste,

GO? HTTP ?? ????? ?? ??, ??, ????? IP ? ?? ??? ?? ? ? ????. 1. http.handlerfunc? ???? ????? ????, 2. ??? ???? ?? ?? ??? ?? ??? ??????. ?? ?? ??? ???? ??? ?????? ??? ????? ???? ? ?????. ?? ???? ?? ?? ??, JSON ?? ?? ? ?? ID ??? ?????.

Java 's Garbage Collection (GC)? ???? ???? ???? ??????, ?? ? ??? ??? ? ??? ??? ??? ??? ????. 1.GC? ?? ?? (? : ?? ??, ?? ???, ?? ?? ?)?? ??? ???? ????, ?? ? ??? ??? ???? ?????. 2. ?? ???? ????? ????, ?? ?? ??? ??? ???? ?? ??? ??????. 3. ?? ?? ?? ?? : ??? ?? (Eden, S0, S1)? ?? ????? ?????. ??? ??? ?? ? MajorGC? ???? ? ??? ? ????. Metaspace? ??? ?? ???? ?????. 4. JVM? ??? GC ??? ?????. SerialGC? ??? ?? ????? ?????. ParallelGC? ???? ??????. CMS? ?? ???

??? htmlinput ??? ???? ??? ???? ????? ??? ??? ?? ??? ???? ???? ? ????. 1. ???, ???, ??, ?? ? ??? ?? ??? ??? ?? ?? ?? ??? ???? ???? ??? ? ???? ??? ? ????. 2. HTML5? ?????? ??? ? ?? ?? ??? ?? ? ??? URL, ??, ?? ? ??? ?? ??? ??? ??????. 3. ?? ?? ? ? ??? ??? ???? ?? ??? ???? ???? ?? ???? ?? ???? ???? ?? ? ? ??? ?? ???????.

GradleisBetTerChoiceFormostNewProjectSduetoitssuperiorflexible, Performance, and ModernToolingsupport.1.Gradle'Sgroovy/kotlindslismoreConcisENDEXPRESSIVETHANMAVEN'SVOSEXML.2.GradleOutsMaveninbuildweedweedweedweedweedweedweedweedweedweedweedweedweedweede

DEFER? ??? ???? ?? ??? ??? ???? ? ?????. ?? ??? ?? ? ? ?? ????, ??? ??? ? ?? ?? (LIFO)? ??? ?????. 1. ?? ??? ??? ? ??? ?????. 2. ?? ??? ?? ??? ??? ????? ?????. 3. ?? ? ?? ?? ??? ? ????. 4. ??? ?????? ??? ??? ???? ?????. 5. ?? ??? ???? ?? ??? ?? ??? ?????. ??? ??? ?? ?? ? ???? ???? ? ????.
