SSM模板参考
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns ="http://maven.apache.org/POM/4.0.0"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion > 4.0.0</modelVersion >
<groupId > com.lee</groupId >
<artifactId > ssmbuild</artifactId >
<version > 1.0-SNAPSHOT</version >
<properties >
<maven.compiler.source > 8</maven.compiler.source >
<maven.compiler.target > 8</maven.compiler.target >
</properties >
<dependencies >
<dependency >
<groupId > mysql</groupId >
<artifactId > mysql-connector-java</artifactId >
<version > 8.0.28</version >
</dependency >
<dependency >
<groupId > com.mchange</groupId >
<artifactId > c3p0</artifactId >
<version > 0.9.5.5</version >
</dependency >
<dependency >
<groupId > javax.servlet</groupId >
<artifactId > servlet-api</artifactId >
<version > 2.5</version >
</dependency >
<dependency >
<groupId > javax.servlet.jsp</groupId >
<artifactId > jsp-api</artifactId >
<version > 2.2</version >
</dependency >
<dependency >
<groupId > javax.servlet</groupId >
<artifactId > jstl</artifactId >
<version > 1.2</version >
</dependency >
<dependency >
<groupId > org.mybatis</groupId >
<artifactId > mybatis</artifactId >
<version > 3.5.7</version >
</dependency >
<dependency >
<groupId > org.mybatis</groupId >
<artifactId > mybatis-spring</artifactId >
<version > 2.0.6</version >
</dependency >
<dependency >
<groupId > org.springframework</groupId >
<artifactId > spring-webmvc</artifactId >
<version > 5.3.13</version >
</dependency >
<dependency >
<groupId > org.springframework</groupId >
<artifactId > spring-jdbc</artifactId >
<version > 5.3.18</version >
</dependency >
<dependency >
<groupId > junit</groupId >
<artifactId > junit</artifactId >
<version > 4.12</version >
<scope > test</scope >
</dependency >
<dependency >
<groupId > org.projectlombok</groupId >
<artifactId > lombok</artifactId >
<version > 1.18.22</version >
</dependency >
</dependencies >
<build >
<resources >
<resource >
<directory > src/main/resources</directory >
<includes >
<include > **/*.properties</include >
<include > **/*.xml</include >
</includes >
<filtering > true</filtering >
</resource >
<resource >
<directory > src/main/java</directory >
<includes >
<include > **/*.properties</include >
<include > **/*.xml</include >
</includes >
<filtering > true</filtering >
</resource >
</resources >
</build >
</project >
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 >
<setting name ="logImpl" value ="STDOUT_LOGGING" />
</settings >
<typeAliases >
<package name ="com.lee.pojo" />
</typeAliases >
</configuration >
database.properties
jdbc.driver =com.mysql.cj.jdbc.Driver
jdbc.url =jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8
jdbc.username =root
jdbc.password =ll546546
driver =com.mysql.cj.jdbc.Driver
url =jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8
username =root
password =ll546546
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"
xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >
<import resource ="classpath:spring-dao.xml" />
<import resource ="classpath:spring-service.xml" />
<import resource ="classpath:springmvc-servlet.xml" />
</beans >
spring-dao.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"
xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd" >
<context:property-placeholder location ="classpath:database.properties" />
<bean id ="dataSource" class ="com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name ="driverClass" value ="${jdbc.driver}" />
<property name ="jdbcUrl" value ="${jdbc.url}" />
<property name ="user" value ="${jdbc.username}" />
<property name ="password" value ="${jdbc.password}" />
<property name ="maxPoolSize" value ="30" />
<property name ="minPoolSize" value ="10" />
<property name ="autoCommitOnClose" value ="false" />
<property name ="checkoutTimeout" value ="10000" />
<property name ="acquireRetryAttempts" value ="2" />
</bean >
<bean id ="sqlSessionFactory" class ="org.mybatis.spring.SqlSessionFactoryBean" >
<property name ="dataSource" ref ="dataSource" />
<property name ="configLocation" value ="classpath:mybatis-config.xml" />
</bean >
<bean class ="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name ="sqlSessionFactoryBeanName" value ="sqlSessionFactory" />
<property name ="basePackage" value ="com.lee.dao" />
</bean >
</beans >
spring-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"
xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd" >
<context:component-scan base-package ="com.lee.service" />
<bean id ="bookServiceImpl" class ="com.lee.service.BookServiceImpl" >
<property name ="bookMapper" ref ="bookMapper" />
</bean >
<bean id ="transactionManager" class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name ="dataSource" ref ="dataSource" />
</bean >
</beans >
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/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd" >
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<context:component-scan base-package ="com.lee.controller" />
<bean class ="org.springframework.web.servlet.view.InternalResourceViewResolver" id ="internalResourceViewResolver" >
<property name ="prefix" value ="/WEB-INF/jsp/" />
<property name ="suffix" value =".jsp" />
</bean >
</beans >
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns ="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version ="4.0" >
<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:applicationContext.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 > encoding</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 > encoding</filter-name >
<url-pattern > /*</url-pattern >
</filter-mapping >
<session-config >
<session-timeout > 15</session-timeout >
</session-config >
</web-app >
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现