第一步
<dependencies>
<dependency>
<groupId>junit
</groupId
>
<artifactId>junit
</artifactId
>
<version>4.11</version
>
<scope>test
</scope
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-core
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-beans
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-context
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-tx
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-jdbc
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
<dependency>
<groupId>org
.mybatis
</groupId
>
<artifactId>mybatis
</artifactId
>
<version>3.5.2</version
>
</dependency
>
<dependency>
<groupId>org
.mybatis
</groupId
>
<artifactId>mybatis
-spring
</artifactId
>
<version>1.3.2</version
>
</dependency
>
<dependency>
<groupId>org
.mybatis
</groupId
>
<artifactId>mybatis
-spring
</artifactId
>
<version>1.3.2</version
>
</dependency
>
<dependency>
<groupId>mysql
</groupId
>
<artifactId>mysql
-connector
-java
</artifactId
>
<version>8.0.16</version
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-jdbc
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
<dependency>
<groupId>com
.alibaba
</groupId
>
<artifactId>druid
</artifactId
>
<version>1.1.16</version
>
</dependency
>
前端接收json数据
<dependency>
<groupId>com
.fasterxml
.jackson
.core
</groupId
>
<artifactId>jackson
-core
</artifactId
>
<version>2.9.4</version
>
</dependency
>
<dependency>
<groupId>com
.fasterxml
.jackson
.core
</groupId
>
<artifactId>jackson
-annotations
</artifactId
>
<version>2.9.4</version
>
</dependency
>
<dependency>
<groupId>com
.fasterxml
.jackson
.core
</groupId
>
<artifactId>jackson
-databind
</artifactId
>
<version>2.9.4</version
>
</dependency
>
<dependency>
<groupId>org
.springframework
</groupId
>
<artifactId>spring
-webmvc
</artifactId
>
<version>5.0.7.RELEASE
</version
>
</dependency
>
第二步
<!--实现了两个接口HandlerMapping与HandlerAdapter。
-->
<mvc
:annotation
-driven
/>
<!--静态资源处理 引入静态资源
-->
<mvc
:default-servlet
-handler
/>
<!--视图解析器
-->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name
="prefix" value
="/WEB-INF/views/"/>
<property name
="suffix" value
=".jsp" />
</bean
>
<!--扫描制定包下面的
-->
<context
:component
-scan base
-package="com.itlike"/>
<!--引入 数据库文件
-->
<context
:property
-placeholder location
="classpath:db.properties"/>
<bean id
="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name
="driverClassName" value
="${jdbc.driver}"/>
<property name
="url" value
="${jdbc.url}"/>
<property name
="username" value
="${jdbc.username}"/>
<property name
="password" value
="${jdbc.password}"/>
</bean
>
<!--定义数据源
-->
<bean id
="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name
="dataSource" ref
="dataSource" />
<property name
="configLocation" value
="classpath:mybatis/SqlMapConfig.xml" />
<property name
="mapperLocations" value
="classpath:mapper/*.xml"/>
</bean
>
<!--配置mapper接口 包名扫描地址
-->
<bean
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name
="basePackage" value
="com.bdqn.dao" />
</bean
>
<mvc
:annotation
-driven
/>
jdbc
.driver
=com
.mysql
.cj
.jdbc
.Driver
jdbc
.url
=jdbc
:mysql
://localhost
:3306/curd
?serverTimezone
=UTC
jdbc
.username
=root
jdbc
.password
=root
第三步
<?xml version
="1.0" encoding
="UTF-8" ?>
<!DOCTYPE mapper PUBLIC
"-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace
="com.itlike.dao.GoodsDao">
<select id
="selectGoods" resultType
="com.itlike.pojo.Goods">
select
* from goods
</select
>
</mapper
>
第四步
<web
-app xmlns
="http://java.sun.com/xml/ns/javaee"
xmlns
:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi
:schemaLocation
="http
://java
.sun
.com
/xml
/ns
/javaee
http
://java
.sun
.com
/xml
/ns
/javaee
/web
-app_3_0
.xsd"
version
="3.0"
metadata
-complete
="false">
<absolute
-ordering
/>
<display
-name
>web
</display
-name
>
<welcome
-file
-list
>
<welcome
-file
>index
.html
</welcome
-file
>
<welcome
-file
>index
.jsp
</welcome
-file
>
</welcome
-file
-list
>
<!--配置前端控制器
-->
<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
*:application
.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
>
<!-- 编码过滤器
-->
<filter>
<filter
-name
>CharacterEncoding
</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
>CharacterEncoding
</filter
-name
>
<url
-pattern
>
第五步
maven配置
<mirror>
<id>alimaven
</id
>
<mirrorOf>central
</mirrorOf
>
<name>aliyun maven
</name
>
<url>http
://maven
.aliyun
.com
/nexus
/content
/groups
/public/</url
>
</mirror
>
<localRepository>E
:/mytails
/apache
-maven
-3.5.4/LocalRepository
</localRepository
>
jdk环境变量
mysql maven 等配置方法一致 可以直接在path里路径写到bin目录
转载请注明原文地址:https://blackberry.8miu.com/read-33585.html