当前位置:网站首页>SSM整合
SSM整合
2022-06-24 09:43:00 【梦及海深@无】
1、导包
<!--导入我们的Servlet的API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--导入我们jstl的标签库的包 -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
<version>1.2.5</version>
</dependency>
<!--第一步应该导入我们的mybatis的包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.4</version>
</dependency>
<!--导入我们的mybatis运行的时候的一些依赖包日志相关的 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--导入的是日志相关的包 -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!--带入cglib代理的包 -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.4</version>
</dependency>
<!--这个就是咋们的这个插件的包-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!--引入junit类 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!--导入myBatis和Spring整合的中间包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.0</version>
</dependency>
<!--导入我们Spring的相关包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<!--介入aspectj的相关包 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<!--MySQL的驱动包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.23.1-GA</version>
</dependency>
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.1.12</version>
</dependency>
2、编写web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!--配置Spring-->
<!--引入Spring的配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--配置SpringMVC-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
3、编写bean-ibatis.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" 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 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--配置数据库的连接池-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="jdbc:mysql:///lkx"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
</bean>
<!--配置SqlSessionfactorybean这个对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>
<!--配置那个MapperScannerConfigurer-->
<bean id="scannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
<property name="basePackage" value="com.qf.ibatis.mapper"></property>
</bean>
<!--配置aop的自动代理-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!--配置包的扫描-->
<context:component-scan base-package="com.qf.ibatis"></context:component-scan>
</beans>
4、编写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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--使能MVC的注解-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--配置的是SpringMVC的扫描-->
<context:component-scan base-package="com.qf.ibatis.controller"></context:component-scan>
</beans>
5、编写Controller
package com.qf.ibatis.controller;
import com.qf.ibatis.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/** * @Auther: lkx * @Date: 2021/3/10 15:55 * @Description: */
@Controller
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("add")
public String add(){
userService.add();
return "/index.jsp";
}
}
6、编写Service
package com.qf.ibatis.service.impl;
import com.qf.ibatis.mapper.UserMapper;
import com.qf.ibatis.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/** * @Auther: lkx * @Date: 2021/3/10 15:56 * @Description: */
@Service
public class UserService implements IUserService {
@Autowired
private UserMapper userMapper;
@Override
public void add() {
userMapper.add();
}
}
7、编写mapper
public interface UserMapper {
/** * 添加用户 */
void add();
}
8、编写mapper.xml
<?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">
<!--下面的这个userMapper是可以随便写的 这个的意思是命名空间 只要这个值在这个系统中是唯一的就可以了 你不可以写两个名字一样的nameSpace 一般的写法就是pojo对象Mapper,这样就见名之意了 -->
<mapper namespace="com.qf.ibatis.mapper.UserMapper">
<!--这里就是使用标签来进行方法的描述-->
<insert id="add">
insert into t_user(userName,password) values("lkx","123");
</insert>
</mapper>
边栏推荐
- js单例模式
- 413 binary tree Foundation
- Engine localization adaptation & Reconstruction notes
- Machine learning - principal component analysis (PCA)
- SQL sever基本数据类型详解
- MySQL data advanced
- CICFlowMeter源码分析以及为满足需求而进行的修改
- 读取csv(tsv)文件出错
- Get the QR code of wechat applet with parameters - and share the source code of modifying the QR code logo
- uniapp 开发微信公众号,下拉框默认选中列表第一个
猜你喜欢

411 stack and queue (20. valid parentheses, 1047. delete all adjacent duplicates in the string, 150. inverse Polish expression evaluation, 239. sliding window maximum, 347. the first k high-frequency

js单例模式

415 binary tree (144. preorder traversal of binary tree, 145. postorder traversal of binary tree, 94. inorder traversal of binary tree)

Getting user information for applet learning (getuserprofile and getUserInfo)

二叉树第一部分

GeoGebra 实例 时钟

简单的价格表样式代码

Yolov6: the fast and accurate target detection framework is open source

Practical analysis: implementation principle of APP scanning code landing (app+ detailed logic on the web side) with source code

Binary tree part I
随机推荐
CVPR 2022 oral | NVIDIA proposes an efficient visual transformer network a-vit with adaptive token. The calculation of unimportant tokens can be stopped in advance
canvas管道动画js特效
形状变化loader加载jsjs特效代码
SSH Remote Password free login
np.float32()
413-二叉树基础
Phpstrom code formatting settings
记录一下MySql update会锁定哪些范围的数据
tf.errors
Safety and food security for teachers and students of the trapped Yingxi middle school
Record the range of data that MySQL update will lock
3.员工的增删改查
Get the QR code of wechat applet with parameters - and share the source code of modifying the QR code logo
被困英西中学的师生安全和食物有保障
Groovy obtains Jenkins credentials through withcredentials
Thinkphp5 clear the cache cache, temp cache and log cache under runtime
Operator details
学习整理在php中使用KindEditor富文本编辑器
Mise en œuvre du rendu de liste et du rendu conditionnel pour l'apprentissage des applets Wechat.
小程序 rich-text中图片点击放大与自适应大小问题