Selaa lähdekoodia

【fix】 修改

zhang 2 vuotta sitten
vanhempi
commit
92a80be1e4

+ 0 - 1
springMvc/src/main/webapp/WEB-INF/web.xml

@@ -57,7 +57,6 @@
57 57
   <servlet>
58 58
     <servlet-name>User</servlet-name>
59 59
     <servlet-class>com.web.UserServlet</servlet-class>
60
-    
61 60
   </servlet>
62 61
   <servlet-mapping>
63 62
     <servlet-name>User</servlet-name>

+ 4 - 0
spring_annotation/src/main/java/com/intercepet/MyInterceptor.java

@@ -0,0 +1,4 @@
1
+package com.intercepet;
2
+
3
+public class MyInterceptor {
4
+}

+ 32 - 0
spring_test/src/main/java/com/config/JdbcConfig.java

@@ -0,0 +1,32 @@
1
+package com.config;
2
+
3
+import com.alibaba.druid.pool.DruidDataSource;
4
+import org.springframework.beans.factory.annotation.Value;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+import org.springframework.context.annotation.PropertySource;
8
+import org.springframework.jdbc.core.JdbcTemplate;
9
+
10
+@Configuration
11
+@PropertySource(value = "classpath:jdbc.properties")
12
+public class JdbcConfig {
13
+    @Value("${jdbc.driver}")
14
+    private String driver;
15
+    @Value("${jdbc.url}")
16
+    private String url;
17
+    @Value("${jdbc.username}")
18
+    private String userName;
19
+    @Value("${jdbc.password}")
20
+    private String password;
21
+    @Bean
22
+    public JdbcTemplate getJdbc() {
23
+        DruidDataSource druidDataSource = new DruidDataSource();
24
+        druidDataSource.setDriverClassName(driver);
25
+        druidDataSource.setUrl(url);
26
+        druidDataSource.setUsername(userName);
27
+        druidDataSource.setPassword(password);
28
+        JdbcTemplate jdbcTemplate = new JdbcTemplate();
29
+        jdbcTemplate.setDataSource(druidDataSource);
30
+        return jdbcTemplate;
31
+    }
32
+}

+ 1 - 1
spring_test/src/main/resources/applicationContext.xml

@@ -7,7 +7,7 @@
7 7
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
8 8
 ">
9 9
 
10
-
10
+    <context:component-scan base-package="com"></context:component-scan>
11 11
 
12 12
 
13 13
 </beans>

+ 0 - 23
spring_test/src/main/webapp/WEB-INF/applicationContext.xml

@@ -1,23 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xmlns:context="http://www.springframework.org/schema/context"
6
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
7
-       http://www.springframework.org/schema/beans/spring-beans.xsd
8
-       http://www.springframework.org/schema/context
9
-       https://www.springframework.org/schema/context/spring-context.xsd">
10
-  <!--    <bean id="userService1" class="com.service.impl.UserServiceImpl">-->
11
-  <!--&lt;!&ndash;        <constructor-arg name="userDao" ref="UserDao"></constructor-arg>&ndash;&gt;-->
12
-  <!--    </bean>-->
13
-  <!--    加载外部 properties文件-->
14
-  <!--      <context:property-placeholder location="jdbc.properties"></context:property-placeholder>-->
15
-  <!--    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">-->
16
-  <!--        <property name="driverClassName" value="${jdbc.driver}"></property>-->
17
-  <!--        <property name="url" value="${jdbc.url}"></property>-->
18
-  <!--        <property name="username" value="${jdbc.username}"></property>-->
19
-  <!--        <property name="password" value="${jdbc.password}"></property>-->
20
-  <!--    </bean>-->
21
-  <!--    组件扫描-->
22
-  <context:component-scan base-package="com"></context:component-scan>
23
-</beans>

+ 20 - 40
spring_test/src/main/webapp/WEB-INF/web.xml

@@ -3,45 +3,25 @@
3 3
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
5 5
          version="4.0">
6
-
7
-  <!--解决乱码的过滤器-->
8
-  <filter>
9
-    <filter-name>CharacterEncodingFilter</filter-name>
10
-    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
11
-    <init-param>
12
-      <param-name>encoding</param-name>
13
-      <param-value>UTF-8</param-value>
14
-    </init-param>
15
-  </filter>
16
-  <filter-mapping>
17
-    <filter-name>CharacterEncodingFilter</filter-name>
18
-    <url-pattern>/*</url-pattern>
19
-  </filter-mapping>
20
-
21
-  <!--全局的初始化参数-->
22
-  <context-param>
23
-    <param-name>contextConfigLocation</param-name>
24
-    <param-value>classpath:applicationContext.xml</param-value>
25
-  </context-param>
26
-  <!--Spring的监听器-->
27
-  <listener>
28
-    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
29
-  </listener>
30
-
31
-
32
-  <!--SpringMVC的前端控制器-->
33
-  <servlet>
34
-    <servlet-name>DispatcherServlet</servlet-name>
35
-    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
36
-    <init-param>
37
-      <param-name>contextConfigLocation</param-name>
38
-      <param-value>classpath:spring-mvc.xml</param-value>
39
-    </init-param>
40
-    <load-on-startup>2</load-on-startup>
41
-  </servlet>
42
-  <servlet-mapping>
43
-    <servlet-name>DispatcherServlet</servlet-name>
44
-    <url-pattern>/</url-pattern>
45
-  </servlet-mapping>
6
+    <context-param>
7
+        <param-name>contextConfigLocation</param-name>
8
+        <param-value>classpath:applicationContext.xml</param-value>
9
+    </context-param>
10
+    <listener>
11
+        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
12
+    </listener>
13
+    <servlet>
14
+        <servlet-name>dispatcherServlet</servlet-name>
15
+        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
16
+        <init-param>
17
+            <param-name>contextConfigLocation</param-name>
18
+            <param-value>classpath:spring-mvc.xml</param-value>
19
+        </init-param>
20
+        <load-on-startup>1</load-on-startup>
21
+    </servlet>
22
+    <servlet-mapping>
23
+        <servlet-name>dispatcherServlet</servlet-name>
24
+        <url-pattern>/</url-pattern>
25
+    </servlet-mapping>
46 26
 
47 27
 </web-app>