当前位置:网站首页>2022/5/8 SSM框架整合增删改查(模糊查询+分页)(详细案例)
2022/5/8 SSM框架整合增删改查(模糊查询+分页)(详细案例)
2022-08-07 05:13:00 【Abcdzzr】
目录
6丶配置applicationContext-mybatis.xml文件
1丶项目结构

2丶所需依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.18</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.2</version>
</dependency>
<!-- 引入数据库连接池,c3p0,dbcp,druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<!-- jedis 使用redis-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>3丶配置mybatis-config.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>
<settings>
<!--严格区分大小写,空格-->
<!--STDOUT_LOGGING标准的日志工厂实现-->
<setting name="logImpl" value="STDOUT_LOGGING"/>
<!--autoMappingBehavior开启resultMap自动装配 普通列自动映射,对象列不自动映射-->
<setting name="autoMappingBehavior" value="FULL"/>
<!--开启二级缓存(Mapper)-->
<!-- <setting name="cacheEnabled" value="true"/>-->
</settings>
<typeAliases>
<!--扫描实体类中的别名,扫描后映射文件查询的返回值可以不写entity包-->
<package name="entity"/>
</typeAliases>
</configuration>4丶配置springmvc-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: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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--支持mvc注解-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--扫描Controller包-->
<context:component-scan base-package="controller"></context:component-scan>
<!--放行jsp所有静态资源-->
<mvc:default-servlet-handler></mvc:default-servlet-handler>
<!--配置文件上传组装说明书-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--设置文件上传最大大小(字节)-->
<property name="maxUploadSize" value="500000"></property>
<!--设置文件上传格式-->
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
</beans>5丶配置database.properties文件
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/t139test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
user=root
password=123123
minIdle=45
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
removeAbandonedTimeout=180
removeAbandoned=true6丶配置applicationContext-mybatis.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"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<!--扫描注解-->
<context:component-scan base-package="service,mapper"/>
<!--读取数据库配置文件-->
<context:property-placeholder location="classpath:database.properties"/>
<!-- JNDI获取数据源(使用dbcp连接池) -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close" scope="singleton">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${user}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
<property name="maxWait" value="${maxWait}"/>
<property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/>
<property name="removeAbandoned" value="${removeAbandoned}"/>
<!-- sql 心跳 -->
<!--开启Evict的定时校验,循环校验 -->
<property name= "testWhileIdle" value="true"/>
<!-- 在进行borrowObject处理时,会对拿到的 连接进行校验-false-->
<property name= "testOnBorrow" value="false"/>
<!-- 在进行ruturnObject处理时,会对返回的连接进行校验-false -->
<property name= "testOnReturn" value="false"/>
<!-- 校验使用的sql语句,validatetionQuery,复杂的校验sql会影响性能 -->
<property name= "validationQuery" value="select 1"/>
<!-- 定义Evict的时间间隔,单位:毫秒 -->
<property name= "timeBetweenEvictionRunsMillis" value="60000"/>
<!-- 配置每次校验连接的数量,一般等于maxActive -->
<property name= "numTestsPerEvictionRun" value="${maxActive}"/>
</bean>
<!--事务管理-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置mybatis sqlsessionFactoryBean-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<!--接口扫描包-->
<!--优先扫描接口中的注解,没有的话会自动去找xml映射文件-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="mapper"/>
</bean>
</beans>7丶配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0">
<!--关联spring核心配置文件,让其生效-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<!--过滤乱码问题-->
<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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--整个项目的监听器,如果缺失那么整个项目的配置文件将会找不到-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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:springmvc-servlet.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>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>8丶运行效果
8.1丶首页界面

8.2丶 组合查询+分页

8.3丶添加



8.4丶修改

8.5丶删除


边栏推荐
猜你喜欢

页面底部出现横向滚动条解决方法

预约家教老师上门辅导小程序开发制作功能介绍

Linear Algebra Study Notes 4-1: Mathematical and Geometric Meaning of Linear Equations, Null Space/Solution Space/Kernel

Excel合并单元格测试代码

Mysql查询数据库有多少张表

Sigrity PowerDC Simulation

Differences in the soft serial port bit time function of different series of STC microcontrollers

一周活动速递|深入浅出第8期;Meetup成都站报名进行中

Talk about 7 magic skills of Redis memory optimization

Seq2Seq superficial understanding
随机推荐
Redis 三个特殊数据类型之Geospatail、Hyperloglog、bitMaps
2021-01-23
[Unity] 获取组件
happens-before rule and thread singleton safety exercise
富滇银行完成数字化升级|OceanBase数据库助力布局分布式架构中台
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
洛谷P1227 完美的对称
NSSCTF Round#4 Web WP
2021-01-18
Redis 常用数据类型之 hash(哈希)
Redis 事务说明与 watch 命令监控事务
高并发思路
Linear Algebra Study Notes 3-4: Describe the spatial compression of linear transformations (column space, rank)
[Graduation Project] Automatic gas station refueling system based on STM32 - Internet of Things, microcontroller, embedded
Sigrity PowerDC Simulation
用C语言实现简单得通讯录
IDEA 2022.2 released
远程连接 redis 时,报错 (error) DENIED Redis is running in protected mode because protected mode is enabled
Linear algebra study notes 4-3: Solving homogeneous linear equations Ax=0, elimination method, row minimum echelon matrix RRFE
This指向问题