您好,登錄后才能下訂單哦!
小編給大家分享一下spring+springmvc+mybatis+maven的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
一、新建maven項目
一般通過這種方法新建maven項目
假如你的eclipse不能通過上面的方法新建maven項目,也可以通過下面的方法新建maven項目
看到下面的項目結(jié)構(gòu),說明你已經(jīng)成功創(chuàng)建了一個maven項目。但是這個項目報錯,根據(jù)標準的web項目結(jié)構(gòu)來說,目前這個項目缺少了web.xml
利用eclipse自動生成web.xml
看到這個項目已經(jīng)沒有報錯,說明已經(jīng)成功生成了web.xml
二、Maven配置
下面是該項目的maven配置,在pom.xml進行以下配置
<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.wffanshao</groupId> <artifactId>test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <!-- Spring版本號 --> <spring.version>4.3.6.RELEASE</spring.version> </properties> <dependencies> <!-- Spring依賴包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <!-- springmvc依賴包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!-- MyBatis依賴包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.2</version> </dependency> <!-- Spring、MyBatis集成包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.1</version> </dependency> <!-- AOP依賴包 --> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> </dependency> <!-- MySQL驅(qū)動包 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.44</version> </dependency> <!-- 數(shù)據(jù)庫連接池依賴包 --> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <!-- JSP標準標簽庫 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- 日志依賴包 --> <!-- 第一種,不推薦 可以用于學(xué)習(xí)log4j,正式項目中不推薦使用,這樣是依賴具體的log4j日志系統(tǒng)。 --> <!-- <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.0-rc1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.0-rc1</version> </dependency> --> <!-- 第二種,博主推薦這種 一般創(chuàng)建工程,建議通過slf4j設(shè)計日志系統(tǒng),方便擴展 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.5</version> </dependency> <!-- 動態(tài)加載依賴包 --> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.18.1-GA</version> </dependency> </dependencies> <build> <!-- 指定打包后文件的名字,例如test.war --> <finalName>test</finalName> <plugins> <!-- 指定jdk版本為1.8 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> <!-- 配置阿里巴巴maven節(jié)點,下載速度比較快 --> <repositories> <repository> <id>people.apache.snapshots</id> <url> http://repository.apache.org/content/groups/snapshots-group/ </url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </project>
三、搭建ssm環(huán)境
1.在src/main/java新建4個包、在src/main/resources下新建2個包以及2個properties文件、在webapp/WEB-INF下新建1個文件夾,包名、文件名以及文件夾名如圖所示。
src/main/java:一般用來存放java文件
src/main/resources:一般用來存放ssm相關(guān)的配置文件
src/test/java和src/test/resources:一般用來存放測試文件,這兩個包下的文件不會被編譯、打包等
webapp/WEB-INF:一般用來存放普通用戶訪問不到而管理員可以訪問的web動態(tài)頁面
2.配置log4j日志文件
log4j.properties代碼如下,有些網(wǎng)友在復(fù)制樓主的代碼會產(chǎn)生亂碼,這是由于eclipse的properties文件默認編碼為ISO-8859-1
我們需要將編碼設(shè)置為UTF-8
##### Global logging configuration ##### 在開發(fā)環(huán)境下日志級別設(shè)置成DEBUG,生產(chǎn)環(huán)境設(shè)置成INFO或ERROR log4j.rootLogger=DEBUG, stdout ##### mybatis日志配置 log4j.logger.org.mybatis.example.BlogMapper=TRACE ##### 輸出到控制臺,這里也可以輸出到文件中,可以自己設(shè)置 log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
3.配置數(shù)據(jù)源文件
db.properties代碼如下,此處采用非硬編碼的方式對數(shù)據(jù)源進行配置,也就是將數(shù)據(jù)源相關(guān)信息配置到db.properties中,采用非硬編碼的好處是方便項目日后的維護以及方便拓展。當然你也可是采用硬編碼方式(傳統(tǒng)方式)進行配置,也就是直接在spring配置文件中配置。
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/ssm jdbc.username=root jdbc.password=test
4.在mysql中新建ssm數(shù)據(jù)庫,并在ssm數(shù)據(jù)庫中新建一個user表,表的結(jié)構(gòu)如圖所示
5.com.wffanshao.po中新建一個PO類,名字為User
User.java的代碼如下
package com.wffanshao.po; /** * @描述 用戶PO類 * @author WF帆少 * @微信 13025261795 * */ public class User { private String username; // 用戶名 private String password; // 用戶密碼 public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
6.在com.wffanshao.mapper中新建UserMapper接口和UserMapper.xml
UserMapper.java代碼如下
package com.wffanshao.mapper; import com.wffanshao.po.User; /** * @描述 用戶Mapper接口 * @author WF帆少 * @微信 13025261795 * */ public interface UserMapper { /** * @描述 添加用戶 * @param user * @throws Exception */ boolean insertUser(User user) throws Exception; }
UserMapper.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" > <mapper namespace="com.wffanshao.mapper.UserMapper"> <!-- 添加用戶 --> <insert id="insertUser" parameterType="User" > <!-- 使用動態(tài)sql,通過if判斷,滿足條件進行sql拼接 --> <if test="username != null and password != null"> INSERT INTO user(username, password) VALUES(#{username}, #{password}) </if> </insert> </mapper>
7.在com.wffanshao.service中新建UserService接口
UserService.java代碼如下
package com.wffanshao.service; import com.wffanshao.po.User; /** * @描述 用戶Service接口 * @author WF帆少 * @微信 13025261795 * */ public interface UserService { /** * @描述 添加用戶 * @param user * @throws Exception */ boolean insertUser(User user) throws Exception; }
8.在com.wffanshao.service.impl中新建UserServiceImpl類
UserServiceImpl.java代碼如下
package com.wffanshao.service.impl; import org.springframework.beans.factory.annotation.Autowired; import com.wffanshao.mapper.UserMapper; import com.wffanshao.po.User; import com.wffanshao.service.UserService; /** * @描述 用戶Service接口的實現(xiàn)類 * @author WF帆少 * @微信 13025261795 * */ public class UserServiceImpl implements UserService{ @Autowired private UserMapper userMapper; /** * @描述 添加用戶 * @param user * @throws Exception */ @Override public boolean insertUser(User user) throws Exception { return userMapper.insertUser(user); } }
9..在com.wffanshao.controller中新建UserController類
UserController.java代碼如下
package com.wffanshao.controller; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import com.wffanshao.po.User; import com.wffanshao.service.UserService; /** * @描述 用戶Controller * @author WF帆少 * @微信 13025261795 * */ @Controller public class UserController { @Autowired private UserService userService; /** * @描述 跳轉(zhuǎn)到login.jsp * @return */ @GetMapping("/login") public String login() { return "login"; } /** * @描述 從login.jsp中的表單提交中獲取數(shù)據(jù)并將它們添加到數(shù)據(jù)庫中, * @return 如果添加成功,跳轉(zhuǎn)到success.jsp,否則,跳轉(zhuǎn)到fail.jsp */ @PostMapping("/insertUser") public String insertUser(HttpServletRequest request) throws Exception { User user = new User(); String username = request.getParameter("username"); String password = request.getParameter("password"); user.setUsername(username); user.setPassword(password); boolean isSuccess = false; isSuccess = userService.insertUser(user); if (isSuccess) { return "success"; } else { return "fail"; } } }
10.在webapp/WEB-INF/jsp下新建login.jsp、success.jsp、fail.jsp
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>注冊</title> </head> <body> <form action="${pageContext.request.contextPath }/insertUser" method="post"> <table> <tr> <td>用戶名:</td> <td><input type="text" name="username"></td> </tr> <tr> <td>密碼:</td> <td><input type="password" name="password"></td> </tr> <tr> <td> <input type="submit" value="注冊"> </td> </tr> </table> </form> </body> </html>
success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>注冊成功</title> </head> <body> <h3>注冊成功</h3> </body> </html>
fail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>注冊失敗</title> </head> <body> <h3>注冊失敗</h3> </body> </html>
11.在src/main/resources/spring中新建4個xml文件
application-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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- 加載db.properties文件中的內(nèi)容,db.properties文件中key命名要有一定的特殊規(guī)則 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 配置數(shù)據(jù)源,dbcp --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="maxActive" value="30"/> <property name="maxIdle" value="5"/> </bean> <!-- sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 數(shù)據(jù)庫連接池 --> <property name="dataSource" ref="dataSource" /> <!-- 加載mybatis的全局配置文件 --> <property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" /> </bean> <!-- mapper掃描器 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 掃描包路徑,如果需要掃描多個包,中間用半角逗號隔開--> <property name="basePackage" value="com.wffanshao.mapper"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> </beans>
application-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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- 用戶的service --> <bean id="userService" class="com.wffanshao.service.impl.UserServiceImpl"></bean> </beans>
applicationContext-transaction.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" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- 事務(wù)管理器 對mybatis操作數(shù)據(jù)庫的事務(wù)控制,spring使用jdbc的事務(wù)控制類 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 數(shù)據(jù)源 dataSource在applicationContext-dao.xml中配置了 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- 傳播行為 --> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="find*" propagation="SUPPORTS" read-only="true"/> <tx:method name="get*" propagation="SUPPORTS" read-only="true"/> <tx:method name="select*" propagation="SUPPORTS" read-only="true"/> </tx:attributes> </tx:advice> <!-- aop --> <aop:config> <!-- 配置切入點 --> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.wffanshao.service.impl.*.*(..))"/> </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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- 注解(推薦使用) --> <!-- 可以掃描controller、service.... 這里讓掃描controller,指定controller的包 --> <context:component-scan base-package="com.wffanshao.controller"></context:component-scan> <!-- 注解的處理器映射器 --> <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /> --> <!-- 注解的處理器適配器 --> <!-- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" /> --> <!-- 使用mvc:annotation-driver代替上邊注解映射器和注解適配器配置 mvc:annotation-driver默認加載很多的參數(shù)綁定方法, 比如json轉(zhuǎn)換解析器被默認加載了,如果使用mvc:annotation-driver不用配置上邊RequestMappingHandlerMapping,RequestMappingHandlerAdapter 實際開發(fā)時使用mvc:annotation-driven conversion-service:自定義參數(shù)綁定的注入 --> <mvc:annotation-driven></mvc:annotation-driven> <!-- 靜態(tài)資源解析 包括:js、css、img.... --> <!-- <mvc:resources location="/js/" mapping="/js/**"/> --> <!-- 視圖解析器 解析jsp解析,默認使用jstl標簽 ,classpath下的有jstl的包 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 配置jsp路徑的前綴 --> <property name="prefix" value="/WEB-INF/jsp/" /> <!-- 配置jsp路徑的后綴 --> <property name="suffix" value=".jsp" /> </bean> <!-- 自定義參數(shù)綁定 --> <!-- <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> 轉(zhuǎn)換器 <property name="converters"> 日期類型轉(zhuǎn)換 <bean class="com.wffanshao.controller.converter.CustomDateConverter"></bean> </property> </bean> --> <!-- 配置校驗器 --> <!-- <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> 校驗器,使用hibernate校驗器 <property name="providerClass" value="org.hibernate.validator.HibernateValidator" /> 指定校驗使用的資源文件,在文件中配置校驗錯誤信息,如果不指定則默認使用classpath下面的ValidationMessages.properties文件 <property name="validationMessageSource" ref="messageSource" /> </bean> - -> <!-- 校驗錯誤信息配置文件 --> <!-- <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 資源文件名 <property name="basenames"> <list> <value>classpath:CustomValidationMessage</value> </list> </property> 資源文件編碼格式 <property name="defaultEncoding" value="utf-8" /> 對資源文件內(nèi)容緩存時間,單位秒 <property name="cacheSeconds" value="120" /> </bean> - -> <!-- 全局異常處理器 只要實現(xiàn)HandlerExceptionResolver接口就是全局異常處理器 --> <!-- <bean class="com.wffanshao.exception.CustomExceptionResolver"></bean> --> <!-- 上傳文件 --> <!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 最大文件大小,設(shè)置上傳文件的最大尺寸為5M,-1為不限制大小, <property name="maxUploadSize" > <value>5242880</value> </property> </bean> --> <!-- 攔截器 --> <!-- <mvc:interceptors> 多個攔截器,順序執(zhí)行 <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.wffanshao.interceptor.LoginInterceptor"/> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.wffanshao.interceptor.HandlerInterceptor1"/> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.wffanshao.interceptor.HandlerInterceptor2"/> </mvc:interceptor> </mvc:interceptors> --> </beans>
四、配置tomcat服務(wù)器
注意:博主使用的是tomcat7
這里沒有教大家如何下載安裝配置tomcat服務(wù)器,請大家自行學(xué)習(xí),或者等博主后續(xù)教程補上。這里只教大家如何用eclipse配置tomcat服務(wù)器,需要提前下載解壓安裝好tomcat才能進行此步操作
配置好tomcat服務(wù)器之后,你會發(fā)現(xiàn)項目報錯了
打開查看報錯原因,你會發(fā)現(xiàn)該項目是因為無法解析jsp而報錯,我們可以通過設(shè)置項目屬性來解決該問題,即設(shè)置該項目的運行環(huán)境
設(shè)置完成后你會發(fā)項目已經(jīng)不報錯了
四、裝配項目
將該項目添加到tomcat服務(wù)器中
到這里,已經(jīng)成功將項目裝配到tomcat服務(wù)器中了。
五、啟動tomcat服務(wù)器
啟動服務(wù)器
看到started并且控制臺沒有報錯說明服務(wù)器啟動成功
六、測試
在瀏覽器地址欄中http://localhost:8080/test/login,tomcat服務(wù)器默認端口為8080
接著輸入用戶名和密碼,然后點擊注冊
注冊成功會跳轉(zhuǎn)到成功頁面,并且在數(shù)據(jù)庫中能查詢到我們剛才輸入的用戶名和密碼,
看到下面2張圖所示的內(nèi)容,證明ssm環(huán)境整合成功
以上是“spring+springmvc+mybatis+maven的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。