Android小屋 通过本文主要向大家介绍了springmvc框架详解,springmvc注解详解,springmvc详解,springmvc配置详解,springmvc原理详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
1、下载SpringMVC框架架包,下载地址:
点击下载
点击打开地址如图所示,点击下载即可
然后把相关的jar复制到lib下导入
2、MyBatis(3.4.2)下载
点击下载
MyBatis中文文档地址
点击查看
下载解压之后把jar复制到lib下导入,大概是这样子的
3、jdbc连接库还没有下载。。。这个是5.1.41版本的。。。
点击下载
解压之后这样子。。。
4、fastjson 阿里巴巴的json解析库
点击下载
版本是1.2.24 这个是托管到了github上面的,地址是:点击进入
5、创建WebProject
注意下一步有个选项,如果不勾选,默认是不会生成web.xml的
6、项目创建完毕,把之前的包都弄进来。。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>CoolWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>CoolWeb</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath:application-context.xml</param-value> -->
<param-value>classpath:CoolWeb-servlet.xml</param-value>
</init-param><!-- classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找. -->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 如果不配置servlet-mapping服务器就无法响应/请求 -->
<servlet-mapping>
<servlet-name>CoolWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
</div>
7、在src下创建CoolWeb-servlet.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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.3.xsd">
<!-- 开启SpringMVC注解 -->
<context:component-scan base-package="com.vincent.lwx"/>
<mvc:annotation-driven/>
</beans>
</div>
8、在src下编写ApplicationContext.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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.3.xsd">
<context:component-scan base-package="com.vincent.lwx"/>
<mvc:annotation-driven/>
<!-- User实体类 -->
<bean id="user" class="com.vincent.lwx.bean.User"/>
<!-- 支持上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<!-- max size:10M -->
<property name="maxUploadSize" value="10485760"/>
</bean>
</beans>
</div>
User实体类要在这里注册
9、在src下编写mybatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<!-- 配置数据库连接信息 -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<!-- 注意3306后面是数据库名称 autoReconnect自动重连-->
<property name="url" value="jdbc:mysql://localhost:3306/cool?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true" />
<property name="username" value="root" />
<property name="password" value="root" />
</dataSource

