W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
[Original] The
@Controller
annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API. However, you can still reference Servlet-specific features if you need to.
@Controller
注解表明了一個類是作為控制器的角色而存在的。Spring不要求你去繼承任何控制器基類,也不要求你去實(shí)現(xiàn)Servlet的那套API。當(dāng)然,如果你需要的話也可以去使用任何與Servlet相關(guān)的特性和設(shè)施。
[Original] The
@Controller
annotation acts as a stereotype for the annotated class, indicating its role. The dispatcher scans such annotated classes for mapped methods and detects@RequestMapping
annotations (see the next section).
@Controller
注解可以認(rèn)為是被標(biāo)注類的原型(stereotype),表明了這個類所承擔(dān)的角色。分派器(DispatcherServlet
)會掃描所有注解了@Controller
的類,檢測其中通過@RequestMapping
注解配置的方法(詳見下一小節(jié))。
[Original] You can define annotated controller beans explicitly, using a standard Spring bean definition in the dispatcher’s context. However, the
@Controller
stereotype also allows for autodetection, aligned with Spring general support for detecting component classes in the classpath and auto-registering bean definitions for them.
當(dāng)然,你也可以不使用@Controller
注解而顯式地去定義被注解的bean,這點(diǎn)通過標(biāo)準(zhǔn)的Spring bean的定義方式,在dispather的上下文屬性下配置即可做到。但是@Controller
原型是可以被框架自動檢測的,Spring支持classpath路徑下組件類的自動檢測,以及對已定義bean的自動注冊。
[Original] To enable autodetection of such annotated controllers, you add component scanning to your configuration. Use the spring-context schema as shown in the following XML snippet:
你需要在配置中加入組件掃描的配置代碼來開啟框架對注解控制器的自動檢測。請使用下面XML代碼所示的spring-context schema:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.springframework.samples.petclinic.web"/>
<!-- ... -->
</beans>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: