當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
最新SSM完整模板(Spring+SpringMVC+MybatisPlus)
生活随笔
收集整理的這篇文章主要介紹了
最新SSM完整模板(Spring+SpringMVC+MybatisPlus)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡介
SSM最新的集成模板,將Mybatis換成了MybatisPlus,實現單表增刪改查的封裝更簡化代碼的書寫
項目預覽
項目創建步驟
首先創建一個Maven模板,建立如上圖的項目結構
然后在pom.xml加入相關依賴
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.2.8.RELEASE</version></dependency><!--springmvc的包--><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.5</version></dependency><dependency><groupId>javax.servlet.jsp.jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><dependency><groupId>org.glassfish.web</groupId><artifactId>jstl-impl</artifactId><version>1.2</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.2.8.RELEASE</version></dependency><!-- 整合spring mybatis的依賴--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.4</version></dependency><!--mysql數據庫的驅動包--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.38</version></dependency><!--mybatis的分頁插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.1.11</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.10.3</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.3</version></dependency><!-- 導入mybatis-plus相關依賴,里面已經包含了mybatis的核心jar包 --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId><version>3.0.1</version></dependency><!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-core --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-core</artifactId><version>3.0.1</version></dependency></dependencies>配置文件如下?
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"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 https://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 https://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 引入小配置文件--><context:property-placeholder location="classpath:jdbc.properties" system-properties-mode="NEVER"/><!-- 配置數據庫連接信息 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="url" value="${url}"></property><property name="driverClassName" value="${driverName}"></property><property name="username" value="${username}"></property><property name="password" value="${pwd}"></property></bean><!--管理mybatis的數據庫連接sqlSession對象--><bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><!--mybatis會為這個包里面的類起別名,映射文件就可以使用這些別名--><property name="typeAliasesPackage" value="com.baidu.entity"/><!--注冊映射文件的--><property name="mapperLocations"><list><value>classpath:dao/*Dao.xml</value></list></property><property name="plugins"><array><bean class="com.github.pagehelper.PageInterceptor"/></array></property></bean><!--讓spring掃描dao包,創建出dao接口的實現類,并把實現類配置為bean標簽UserDao=======userDaoBookDao=====bookDao--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="dao"/></bean><!-- <bean id="bs" class="com.baidu.service.impl.xxServiceImpl"><property name="bd" ref="xxDao"/></bean> --><!--事務管理器--><bean id="tm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!--把事務管理器注入到事務通知類--><tx:advice id="txAdvice" transaction-manager="tm"><!--事務的策略,類中不同方法使用不同的事務策略--><tx:attributes><!--以select的方法,都是只讀的方法,不用使用事務--><tx:method name="select*" read-only="true"/><tx:method name="find*" read-only="true"/><!--除了select開頭的方法,其余的方法都必須使用事務--><tx:method name="*" propagation="REQUIRED"/></tx:attributes></tx:advice><!--配置切入點和織入--><aop:config><aop:pointcut id="pc" expression="execution(* com.baidu.service..*.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/></aop:config> </beans>springmvc.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:mvc="http://www.springframework.org/schema/mvc"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 http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--掃描控制器包,讀取注解--><context:component-scan base-package="com.baidu.controller"/><!--開啟mvc的注解功能--><mvc:annotation-driven/> </beans>jdbc.properties?
url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8 driverName=com.mysql.jdbc.Driver username=root pwd=rootweb.xml?
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--配置springmvc配置文件的位置--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><!--處理post請求亂碼的過濾器--><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><filter><filter-name>AccessControlAllowFilter</filter-name><filter-class>com.baidu.filter.AccessControlAllowFilter</filter-class></filter><filter-mapping><filter-name>AccessControlAllowFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener> </web-app>總結
以上是生活随笔為你收集整理的最新SSM完整模板(Spring+SpringMVC+MybatisPlus)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 可用资源不足excel无法完成任务_项目
- 下一篇: 【请收藏】自动化构建部署之Circle