当前位置: 首页 > news >正文

maven聚合ssm

如果没有写过ssm项目请移步SSM后端框架搭建(有图有真相)-CSDN博客

数据库准备

create table `user` (`id` int (11),`uid` varchar (60),`name` varchar (60),`age` int (11),`sex` varchar (12)
); 
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('10','20240909','张三丰','9999','男');
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('11','20240907','张无忌','111','男');
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('12','12010909','郭靖','11','男');
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('13','22222222','黄蓉','18','女');
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('14','43215678','赵敏','18','女');
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('15','78787878','杨过','22','男');
insert into `user` (`id`, `uid`, `name`, `age`, `sex`) values('18','12344321','小龙女','18','女');

1.创建父项目

首先创建一个空项目

删除src目录,并整理pom.xml文件

在标签中引入项目所需的所有依赖(如下)并刷新

<!--mysql-->
<dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.32</version>
</dependency><!--德鲁伊-->
<dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.0.9</version>
</dependency><!--mybatis-->
<dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.5</version>
</dependency><!--单元测试-->
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.1</version>
</dependency><!--补充实体类-->
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.30</version>
</dependency><!--spring上下文核心-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.20</version>
</dependency><!--代替单元测试-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.3.20</version>
</dependency><!--spring 事务-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.3.20</version>
</dependency><!--spring切面-->
<dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.9</version>
</dependency><!--springtemplate-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.20</version>
</dependency><!--mybatis整合spring坐标-->
<dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.3.1</version>
</dependency>
<!--springmvc-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.20</version>
</dependency>
<!--servlet-->
<dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version>
</dependency>
<!--支持jsp-->
<dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version>
</dependency>
<!--标准标签库-->
<dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version>
</dependency>
<!--日志-->
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.36</version>
</dependency>
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.36</version>
</dependency>
<!--支持web-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.3.20</version>
</dependency>
<!--解析xml-->
<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.9.6</version>
</dependency>
<!--文件上传-->
<dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.3</version>
</dependency>
<dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.6</version>
</dependency>
<!--分页助手-->
<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.2.0</version>
</dependency>
<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.76</version>
</dependency>

2.创建mapper层

在父模块下新建子模块

整理pom.xml文件

构建mapper模块的结构

在resources创建spring配置文件applicationContext-mapper.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:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--注解组件扫描--><context:component-scan base-package="com.myself.mapper"/><!--spring整合mybatis--><context:property-placeholder location="classpath:druid.properties"/><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driverClassName}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!--SqlSessionFactory创建交给spring的IOC容器--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--数据库环境配置--><property name="dataSource" ref="dataSource"/><!--类型别名配置--><property name="typeAliasesPackage" value="com.myself.pojo"/><!--如果要引入mybatis主配置文件,可以通过如下配置--><!--<property name="configLocation" value="classpath:SqlMapConfig.xml"/>--></bean><!--映射接口扫描配置,由spring创建代理对象,交给IOC容器--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.myself.mapper"/></bean><!--事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!--开启事务注解支持--><tx:annotation-driven/>
</beans>

在resources创建数据库连接文件

jdbc.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db1?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
jdbc.username=root
jdbc.password=123456initialSize=5
maxActive=10
maxWait=3000

创建User对象

@Data
public class User {private int id;private String uid;private String name;private int age;private String sex;
}

在UserMapper创建接口

在其对应的映射文件中实现

<?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.myself.mapper.UserMapper"><select id="findAll" resultType="com.myself.pojo.User">select * from user;</select>
</mapper>

在test中创建测试类

3.创建service层

在父模块下创建子模块

整理pom.xml文件

创建service模块结构

在resources文件下创建spring配置文件applicationContext-service.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:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--注解组件扫描--><context:component-scan base-package="com.myself.service"/><import resource="classpath:applicationContext-mapper.xml"/>
</beans>

在UserService 创建接口 并实现

创建测试类

4.创建web层

在父模块下创建子模块

整理pom.xml文件

构建web子模块结构

在resources下创建springmvc配置文件

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!--组件扫描--><context:component-scan base-package="com.myself.controller"/><!--mvc注解增强--><mvc:annotation-driven/><!--视图解析器 如果前后端分离则不需要--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".jsp"/></bean><!--实现静态资源映射--><mvc:default-servlet-handler/>
</beans>

在resources文件下创建spring配置文件applicationContext-web.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:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><import resource="classpath:applicationContext-service.xml"/></beans>

在web.xml配置文件中加入配置

<!--前端控制器-->
<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:springmvc.xml</param-value></init-param><load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern>
</servlet-mapping>
<!--post中文处理-->
<filter><filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern>
</filter-mapping><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-web.xml</param-value>
</context-param>

在UserController中写入

配置tomcat

测试运行

相关文章:

maven聚合ssm

如果没有写过ssm项目请移步SSM后端框架搭建&#xff08;有图有真相&#xff09;-CSDN博客 数据库准备 create table user (id int (11),uid varchar (60),name varchar (60),age int (11),sex varchar (12) ); insert into user (id, uid, name, age, sex) values(10,202409…...

网络通信与并发编程(二)基于tcp的套接字、基于udp的套接字、粘包现象

基于tcp的套接字 文章目录 基于tcp的套接字一、套接字的工作流程二、基于tcp的套接字通信三、基于udp的套接字通信四、粘包现象 一、套接字的工作流程 Socket是应用层与TCP/IP协议族通信的中间软件抽象层&#xff0c;它是一组接口。在设计模式中&#xff0c;Socket其实就是一个…...

400行程序写一个实时操作系统(十):用面向对象思想构建抢占式内核

前言 通过前几章的学习&#xff0c;我们学会了如何为RTOS设计一个合理的内存管理算法。现在&#xff0c;是时候学习设计RTOS内核了。 关于RTOS内核的文章也有很多&#xff0c;但都有一点先射箭再化靶子的意味。要么是代码连篇解释却寥寥无几&#xff0c;要么是要先怎么样再怎么…...

C#学习笔记(九)

C#学习笔记&#xff08;九&#xff09; 第六章 面向对象编程&#xff08;一&#xff09;类与对象、字段与属性一、类与对象正确的理解1. 什么是类&#xff1f;2.什么是对象&#xff1f;3. 类与对象的区别 二、类的基本规范和对象使用1. 类的规范 三、类的访问修饰符&#xff08…...

意外发现!AI写作这样用,热点文章轻松超越同行90%!

做自媒体&#xff0c;写热点文章很重要。 热点自带流量&#xff0c;能很快吸引不少读者。 可很多自媒体新手很犯愁。 干货文还能勉强写出来&#xff0c;碰到热点文就不知咋办了。 为啥写热点文章这么难呢&#xff1f; 关键是得找个新颖角度切入。 要是只在网上反复复制粘贴那些…...

WPF常见容器全方位介绍

Windows Presentation Foundation (WPF) 是微软的一种用于构建Windows桌面应用程序的UI框架。WPF的布局系统基于容器&#xff0c;帮助开发者以灵活、响应的方式组织用户界面 (UI) 元素。本篇文章将详细介绍WPF中几种常见的容器&#xff0c;包括Grid、StackPanel、WrapPanel、Do…...

重置时把el-tree树节点选中状态取消

要重置 Element UI 的 el-tree 组件并取消所有节点的选中状态&#xff0c;可以通过以下几种方法&#xff1a; 使用 setCheckedKeys 方法&#xff1a; 如果你的树配置了 node-key 属性&#xff0c;可以使用 setCheckedKeys 方法来清空所有选中的节点。 this.$refs.tree.setCheck…...

服务器系统克隆技术

工作任务&#xff1a;克隆对象是Windows server2019 和2022的datacenter版本 条件&#xff1a;在已经完成安装的虚拟机上做克隆 图1-1 用两个服务器的母盘准备进行克隆 第一步&#xff1a;新建一个文件目录用于安放克隆好的服务器 图1-2 创建两个目录用于安放即将克隆好的服务…...

【Java】多线程 Start() 与 run() (简洁实操)

Java系列文章目录 补充内容 Windows通过SSH连接Linux 第一章 Linux基本命令的学习与Linux历史 文章目录 Java系列文章目录一、前言二、学习内容&#xff1a;三、问题描述start() 方法run() 方法 四、解决方案&#xff1a;4.1 重复调用 .run()4.2 重复调用 start()4.3 正常调用…...

基于微信小程序的购物系统【附源码、文档】

博主介绍&#xff1a;✌IT徐师兄、7年大厂程序员经历。全网粉丝15W、csdn博客专家、掘金/华为云//InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;&#x1f3…...

AI绘画:24最新Stable Diffusion 终极炼丹宝典:从入门到精通!

前言 我是咪咪酱&#xff0c;以浅显易懂的方式&#xff0c;与大家分享那些实实在在可行之宝藏。 历经耗时数十个小时&#xff0c;总算将这份Stable Diffusion的使用教程整理妥当。 从最初的安装与配置&#xff0c;细至界面功能的详解&#xff0c;再至实战案例的制作&#xf…...

线性可分支持向量机的原理推导【补充知识部分】拉格朗日函数 公式解析

本文是将文章《线性可分支持向量机的原理推导》中的公式单独拿出来做一个详细的解析&#xff0c;便于初学者更好的理解。在主文章中&#xff0c;有一个部分是关于补充拉格朗日对偶性的相关知识&#xff0c;此公式即为这部分内容。 公式 9-9 是关于拉格朗日函数 L ( x , α , β…...

csdn(最新交流群)

SEOI Chathttps://seoi.net/room/10122?kwe7cp45v此网站开放性较强&#xff0c;小心诈骗...

新手maven入门学习教程

MAVEN基础入门 提示&#xff1a;java新人的学习之路记录 学习内容&#xff1a; 提示&#xff1a;了解并会初步使用maven构建管理java项目 Maven 是一个非常流行的 Java 项目管理和构建工具。它通过提供一套标准的构建生命周期和一组预定义的目标来简化 Java 应用程序的构建过…...

React 中级阶段学习计划

React 中级阶段学习计划 目标 掌握状态管理和路由。能够调用API并处理异步数据。学会使用CSS-in-JS和CSS Modules进行样式处理。 学习内容 状态管理 React Context API Context API&#xff1a;用于在组件树中传递数据&#xff0c;避免多层props传递。示例&#xff1a;im…...

[产品管理-47]:产品市场调研 - 一级市场、二级市场、次级市场?

目录 一、产品销售环节的一级二级市场 1、一级市场 2、二级市场 3、一级市场与二级市场的互动关系 二、金融中的一级二级市场 1、一级市场&#xff08;Primary Market&#xff09;- 新股发行、定向发行 2、二级市场&#xff08;Secondary Market&#xff09;- 普通投资者…...

Linux零基础教程学习(黑马)

1.初识Linux 1.2远程连接Linux系统 图形化、命令行 对于操作系统的使用&#xff0c;有2种使用形式&#xff1a; 图形化页面使用操作系统 以命令的形式使用操作系统 不论是Windows还是Linux亦或是MacOS系统&#xff0c;都是支持这两种使用形式。 图形化&#xff1a;使用操作…...

一款零依赖、跨平台的流媒体协议处理工具,支持 RTSP、WebRTC、RTMP 等视频流协议的处理

大家好&#xff0c;今天给大家分享一款功能强大的流媒体协议处理工具go2rtc&#xff0c;支持多种协议和操作系统&#xff0c;具有零依赖、零配置、低延迟等特点。 项目介绍 go2rtc可以从各种来源获取流&#xff0c;包括 RTSP、WebRTC、HomeKit、FFmpeg、RTMP 等&#xff0c;并…...

PHP 正则验证A-Z且排除某字母

都已经找到这里来了&#xff0c;相信已经尝试很多办法了&#xff0c;那么我们直接上答案 关键正则&#xff1a;(?!.*[IO]) //验证5到6个大写字母且排除I和O if (preg_match(/^(?!.*[IO])[A-Z\d]{5,6}$/u, AAAAM)) {echo "匹配成功"; } else {echo "匹配失败…...

如何安全运行别人上传的Python代码?

写后端的同学&#xff0c;有时候需要在网站上实现一个功能&#xff0c;让用户上传或者编写自己的Python代码。后端再运行这些代码。 涉及到用户自己上传代码&#xff0c;我们第一个想到的问题&#xff0c;就是如何避免用户编写危险命令。如果用户的代码里面涉及到下面两行&…...

国防科技大学计算机基础课程笔记02信息编码

1.机内码和国标码 国标码就是我们非常熟悉的这个GB2312,但是因为都是16进制&#xff0c;因此这个了16进制的数据既可以翻译成为这个机器码&#xff0c;也可以翻译成为这个国标码&#xff0c;所以这个时候很容易会出现这个歧义的情况&#xff1b; 因此&#xff0c;我们的这个国…...

Java 语言特性(面试系列2)

一、SQL 基础 1. 复杂查询 &#xff08;1&#xff09;连接查询&#xff08;JOIN&#xff09; 内连接&#xff08;INNER JOIN&#xff09;&#xff1a;返回两表匹配的记录。 SELECT e.name, d.dept_name FROM employees e INNER JOIN departments d ON e.dept_id d.dept_id; 左…...

python打卡day49

知识点回顾&#xff1a; 通道注意力模块复习空间注意力模块CBAM的定义 作业&#xff1a;尝试对今天的模型检查参数数目&#xff0c;并用tensorboard查看训练过程 import torch import torch.nn as nn# 定义通道注意力 class ChannelAttention(nn.Module):def __init__(self,…...

【OSG学习笔记】Day 18: 碰撞检测与物理交互

物理引擎&#xff08;Physics Engine&#xff09; 物理引擎 是一种通过计算机模拟物理规律&#xff08;如力学、碰撞、重力、流体动力学等&#xff09;的软件工具或库。 它的核心目标是在虚拟环境中逼真地模拟物体的运动和交互&#xff0c;广泛应用于 游戏开发、动画制作、虚…...

微信小程序 - 手机震动

一、界面 <button type"primary" bindtap"shortVibrate">短震动</button> <button type"primary" bindtap"longVibrate">长震动</button> 二、js逻辑代码 注&#xff1a;文档 https://developers.weixin.qq…...

【Oracle】分区表

个人主页&#xff1a;Guiat 归属专栏&#xff1a;Oracle 文章目录 1. 分区表基础概述1.1 分区表的概念与优势1.2 分区类型概览1.3 分区表的工作原理 2. 范围分区 (RANGE Partitioning)2.1 基础范围分区2.1.1 按日期范围分区2.1.2 按数值范围分区 2.2 间隔分区 (INTERVAL Partit…...

分布式增量爬虫实现方案

之前我们在讨论的是分布式爬虫如何实现增量爬取。增量爬虫的目标是只爬取新产生或发生变化的页面&#xff0c;避免重复抓取&#xff0c;以节省资源和时间。 在分布式环境下&#xff0c;增量爬虫的实现需要考虑多个爬虫节点之间的协调和去重。 另一种思路&#xff1a;将增量判…...

零基础在实践中学习网络安全-皮卡丘靶场(第九期-Unsafe Fileupload模块)(yakit方式)

本期内容并不是很难&#xff0c;相信大家会学的很愉快&#xff0c;当然对于有后端基础的朋友来说&#xff0c;本期内容更加容易了解&#xff0c;当然没有基础的也别担心&#xff0c;本期内容会详细解释有关内容 本期用到的软件&#xff1a;yakit&#xff08;因为经过之前好多期…...

A2A JS SDK 完整教程:快速入门指南

目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库&#xff…...

scikit-learn机器学习

# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可: # Also add the following code, # so that every time the environment (kernel) starts, # just run the following code: import sys sys.path.append(/home/aistudio/external-libraries)机…...