1: Installation environment JDK 1.8 JAVA environment variable added
2: Installation IDEA
. 3: Installation Maven environment variable added to modify the configuration file
4: Maven project
5: creation sub-module
6: Add Project dependent
---- Java EE
--javax.servlet -API
- JSP-API
--jstl
---- the Spring
- Spring-Core
- Spring-Beans
- Spring-context
- Spring-expression The
- Spring-AOP
- Spring-Aspects
- Spring-jdbc
-tx - Spring
- Spring-webmvc
---- the mybatis
--mybatis
--mybatis the Spring-
---- pagehelper
--pagehelper
---- MySQL
- MySQL-Connector-the Java
--druid
---- commons
FileUpload---commons
--fastjson
7: Add project dependencies
8: web page to add
9: Modify the web.xml configuration springMVC
<?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"> <!--9.1 添加sevlet配置--> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 添加springXML文件扫描--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!--9.2 springMVC解析路径--> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--9.3 =添加过滤器--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--<error-page>--> <!--<location>12</location>--> <!--</error-page>--> </web-app>
10: Adding springXML file
- add spring-mvc.xml
<?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:mvc="http://www.springframework.org/schema/mvc" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<! - 10.1 = add MVC drive ->
<mvc:annotation-driven/>
<! - adding MVC = 10.2 driver package path ->
<context:component-scan base-package="com.nana.blog.admin.controller"/>
<! - 10.3 = add MVC Routing ->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> <mvc:view-controller path="/showLogin" view-name="login"/> <mvc:resources mapping="/admin/css/**" location="/WEB-INF/static/admin/css/"/> <mvc:resources mapping="/admin/js/**" location="/WEB-INF/static/admin/js/"/> <mvc:resources mapping="/admin/img/**" location="/WEB-INF/static/admin/img/"/> <mvc:resources mapping="/common/**" location="/WEB-INF/static/common/"/> <mvc:resources mapping="/admin/data/**" location="/WEB-INF/data/"/> </beans>
11: Add POJOs
12 is: Add the DAO
13 is: arranged spring-dao.xml
<?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" 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">
<! - 13.1 = add the database link Properties ->
<context:property-placeholder location="classpath:dataSource.properties"/> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${jdbc.driveClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.userName}"/> <property name="password" value="${jdbc.password}"/> <property name="initialSize" value="${jdbc.initialSize}"/> </bean>
<! - 13.2 = add the database plant ->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:com/nana/blog/mapper/*.xml"/> <property name="typeAliasesPackage" value="com.nana.blog.pojo"/> </bean>
<! - package path swept = 13.1 ->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="sqlSessionFactoryBeanName" value="sessionFactory"/> <property name="basePackage" value="com.nana.blog.dao"/> </bean> </beans>
14: Configuring spring-server.xml add transaction configuration
<?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:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:component-scan base-package="com.nana.blog.service.impl"/> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
15: Adding a database mapping file mapper, see mybatis copy xml format
17: Adding a service interface class
18: Adding impl achieve service interface
- declare @Service,
- declared the @Transactional (propagation, rollbackFor)
- injected Dao
19: Web module adds the Controller
- statement @Controller
- page path statement @@ RequestMapping map
- injected @Autowired Object services
20: bind model.addAttribute front-end data processing