新手教你學Spring MVC4.0+MyBatis+MySQL5.0實現簡單使用者註冊登入程式(一)
阿新 • • 發佈:2018-12-31
本篇是實現使用者註冊登入程式的第一篇。
0、 效果預覽篇
1. 使用者註冊
2. 使用者登入
1、專案預覽及環境配置
環境: Win10+Intellij idea+Navicat for mysql+Maven3.0+Spring MVC4.0
專案預覽:
專案採用三層架構:應用顯示層(MVC:Model+View+Controller)、資料持久層(Dao)、Service層。同時採用面向介面的程式設計方式。
2、 資料庫搭建配置篇
在這裡,推薦使用Navicat。。。資料庫名稱為mybatis。表為t_user。
推薦教程: http://www.cr173.com/html/51039_1.html
大家可以通過命令列看到我們安裝的MySQL的版本:select version();
可以看到我的MySQL資料庫的版本為5.1.45-community的版本。
這個至關重要,因為當我們配置MySQL JDBC驅動的時候需要對應的版本。
3、Maven配置篇
主要是專案依賴
<!-- spring-webmvc包含了spring-aop.jar、spring-beans.jar、spring-context.jar、spring-core.jar、spring-web.jar、spring-expression.jar 以及spring-webmvc.jar--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${springframework.version}</version> </dependency> <!-- Mybatis資料庫框架 The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented applications. MyBatis couples objects with stored procedures or SQL statements using a XML descriptor or annotations. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.1</version> </dependency> <!-- An easy-to-use Spring bridge for MyBatis sql mapping framework --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <!-- MySQL JDBC Type 4 driver --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${springframework.version}</version> </dependency>
···
注:
1、指定Spring版本
2、配置依賴:
spring-webmvc、spring-context-support、mybatis、mybatis-spring、mysql-connector-java、spring-tx、spring-jdbc
注意:這裡的mysql-connector-java版本一定為5.XXX具體可以上Maven中央庫上查。如果填寫6的話,就會報如下錯誤: