Spring MVC(大全)
阿新 • • 發佈:2018-12-21
配置web.xml
<web-app> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/app-context.xml</param-value> </context-param> <servlet> <servlet-name>app</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value></param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>app</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> </web-app>
DispatcherServlet請求配置WebApplicationContext
(an extension of a plain ApplicationContext
)
context的分層
Controller的註解:@Controller和@RestController
@RestController註解相當於@ResponseBody + @Controller合在一起的作用
@Configuration
@ComponentScan("org.example.web")
public class WebConfig {
// ...
}
<?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.example.web"/> <!-- ... --> </beans>
如果需要返回JSON,XML或自定義mediaType內容到頁面,則需要在對應的方法上加上@ResponseBody註解。
是偏見讓成見演化為歧視,當歧視升級為某種“政治正確“重壓之下不可避免地陷入懷疑和自我懷疑,最終被歧視者開始自己。絕大多數人沒能同時接受成功和失敗的教育,學會相聚和告別的禮儀,師長、前輩、父母有太多太多的人教導你如何成功和享受成功的101種姿勢。卻很少有人告訴你如何面對意料之外的挫折和分離,成長有時很漫長,有時只是一瞬間的事