spring mvc base init
This commit is contained in:
parent
d28b49db9f
commit
c54d520737
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
*#
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
*.jar
|
||||||
|
*.sw?
|
||||||
|
*~
|
||||||
|
.#*
|
||||||
|
.*.md.html
|
||||||
|
.DS_Store
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.gradle
|
||||||
|
.idea
|
||||||
|
.metadata
|
||||||
|
.project
|
||||||
|
.recommenders
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
/build
|
||||||
|
/code
|
||||||
|
MANIFEST.MF
|
||||||
|
_site/
|
||||||
|
activemq-data
|
||||||
|
bin
|
||||||
|
build
|
||||||
|
build.log
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
dump.rdb
|
||||||
|
interpolated*.xml
|
||||||
|
lib/
|
||||||
|
manifest.yml
|
||||||
|
overridedb.*
|
||||||
|
settings.xml
|
||||||
|
target
|
||||||
|
out
|
||||||
|
transaction-logs
|
||||||
|
.flattened-pom.xml
|
||||||
|
secrets.yml
|
||||||
|
.gradletasknamecache
|
||||||
|
.sts4-cache
|
0
spring-boot/.gitignore
vendored
Normal file
0
spring-boot/.gitignore
vendored
Normal file
0
spring-cloud/.gitignore
vendored
Normal file
0
spring-cloud/.gitignore
vendored
Normal file
1
spring/springmvc-base-annotation/README.md
Normal file
1
spring/springmvc-base-annotation/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
springmvc-base-annotation
|
51
spring/springmvc-base-annotation/pom.xml
Normal file
51
spring/springmvc-base-annotation/pom.xml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.heibaiying</groupId>
|
||||||
|
<artifactId>springmvc-base</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-base-version>5.1.3.RELEASE</spring-base-version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-beans</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 使用注解方式需要加上此包 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>4.0.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.heibaiying.config;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : heibaiying
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||||
|
|
||||||
|
protected Class<?>[] getRootConfigClasses() {
|
||||||
|
return new Class[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<?>[] getServletConfigClasses() {
|
||||||
|
return new Class[]{ServletConfig.class};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] getServletMappings() {
|
||||||
|
return new String[]{"/"};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.heibaiying.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.ViewResolver;
|
||||||
|
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : heibaiying
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
@ComponentScan(basePackages = {"com.heibaiying.controller"})
|
||||||
|
public class ServletConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置视图解析器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ViewResolver viewResolver() {
|
||||||
|
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
|
||||||
|
internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");
|
||||||
|
internalResourceViewResolver.setSuffix(".jsp");
|
||||||
|
internalResourceViewResolver.setExposeContextBeansAsAttributes(true);
|
||||||
|
return internalResourceViewResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置静态资源处理器
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||||
|
configurer.enable();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.heibaiying.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : heibaiying
|
||||||
|
* @description : hello spring
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("mvc")
|
||||||
|
public class HelloController {
|
||||||
|
|
||||||
|
@RequestMapping("hello")
|
||||||
|
private String hello() {
|
||||||
|
return "hello";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Hello Spring MVC!
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,9 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>index</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
INDEX!
|
||||||
|
</body>
|
||||||
|
</html>
|
1
spring/springmvc-base/README.md
Normal file
1
spring/springmvc-base/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
springmvc-base
|
44
spring/springmvc-base/pom.xml
Normal file
44
spring/springmvc-base/pom.xml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.heibaiying</groupId>
|
||||||
|
<artifactId>springmvc-base</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-base-version>5.1.3.RELEASE</spring-base-version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-beans</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${spring-base-version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.heibaiying.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : heibaiying
|
||||||
|
* @description : hello spring
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("mvc")
|
||||||
|
public class HelloController {
|
||||||
|
|
||||||
|
@RequestMapping("hello")
|
||||||
|
private String hello() {
|
||||||
|
return "hello";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
<?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:context="http://www.springframework.org/schema/context"
|
||||||
|
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||||
|
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-4.1.xsd
|
||||||
|
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
|
||||||
|
|
||||||
|
<!-- 开启注解包扫描-->
|
||||||
|
<context:component-scan base-package="com.heibaiying.*"/>
|
||||||
|
|
||||||
|
<!--使用默认的Servlet来响应静态文件 详见README.md -->
|
||||||
|
<mvc:default-servlet-handler/>
|
||||||
|
|
||||||
|
<!-- 开启注解驱动 详见 README.md -->
|
||||||
|
<mvc:annotation-driven/>
|
||||||
|
|
||||||
|
<!-- 配置视图解析器 -->
|
||||||
|
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
|
||||||
|
id="internalResourceViewResolver">
|
||||||
|
<!-- 前缀 -->
|
||||||
|
<property name="prefix" value="/WEB-INF/jsp/"/>
|
||||||
|
<!-- 后缀 -->
|
||||||
|
<property name="suffix" value=".jsp"/>
|
||||||
|
</bean>
|
||||||
|
</beans>
|
@ -0,0 +1,9 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Hello Spring MVC!
|
||||||
|
</body>
|
||||||
|
</html>
|
24
spring/springmvc-base/src/main/webapp/WEB-INF/web.xml
Normal file
24
spring/springmvc-base/src/main/webapp/WEB-INF/web.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||||
|
version="3.1">
|
||||||
|
|
||||||
|
<!--配置spring前端控制器-->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>springMvc</servlet-name>
|
||||||
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>contextConfigLocation</param-name>
|
||||||
|
<param-value>classpath:springApplication.xml</param-value>
|
||||||
|
</init-param>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>springMvc</servlet-name>
|
||||||
|
<url-pattern>/</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
</web-app>
|
9
spring/springmvc-base/src/main/webapp/index.jsp
Normal file
9
spring/springmvc-base/src/main/webapp/index.jsp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>index</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
INDEX!
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user