SpringMVC入門學習案例筆記
阿新 • • 發佈:2018-04-08
res 如圖所示 ring mes 小明 生日 class 描述 innodb
一、數據庫環境用mysql,數據庫建表語句如下:
/* SQLyog v10.2 MySQL - 5.1.72-community : Database - mybatis ********************************************************************* */ /*!40101 SET NAMES utf8 */; /*!40101 SET SQL_MODE=‘‘*/; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0*/; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; /*Table structure for table `items` */ DROP DATABASE IF EXISTS `mybatis`; CREATE DATABASE `mybatis` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `mybatis`; SETFOREIGN_KEY_CHECKS=0; DROP TABLE IF EXISTS `items`; CREATE TABLE `items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL COMMENT ‘商品名稱‘, `price` float(10,1) NOT NULL COMMENT ‘商品定價‘, `detail` text COMMENT ‘商品描述‘, `pic` varchar(64) DEFAULT NULL COMMENT ‘商品圖片‘, `createtime`datetime NOT NULL COMMENT ‘生產日期‘, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; insert into `items`(`id`,`name`,`price`,`detail`,`pic`,`createtime`) values (1,‘臺式機‘,3000.0,‘該電腦質量非常好!!!!‘,NULL,‘2015-02-03 13:22:53‘),(2,‘筆記本‘,6000.0,‘筆記本性能好,質量好!!!!!‘,NULL,‘2015-02-09 13:22:57‘),(3,‘背包‘,200.0,‘名牌背包,容量大質量好!!!!‘,NULL,‘2015-02-06 13:23:02‘); /*Table structure for table `orderdetail` */ DROP TABLE IF EXISTS `orderdetail`; CREATE TABLE `orderdetail` ( `id` int(11) NOT NULL AUTO_INCREMENT, `orders_id` int(11) NOT NULL COMMENT ‘訂單id‘, `items_id` int(11) NOT NULL COMMENT ‘商品id‘, `items_num` int(11) DEFAULT NULL COMMENT ‘商品購買數量‘, PRIMARY KEY (`id`), KEY `FK_orderdetail_1` (`orders_id`), KEY `FK_orderdetail_2` (`items_id`), CONSTRAINT `FK_orderdetail_1` FOREIGN KEY (`orders_id`) REFERENCES `orders` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_orderdetail_2` FOREIGN KEY (`items_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; insert into `orderdetail`(`id`,`orders_id`,`items_id`,`items_num`) values (1,3,1,1),(2,3,2,3),(3,4,3,4),(4,4,2,3); /*Table structure for table `orders` */ DROP TABLE IF EXISTS `orders`; CREATE TABLE `orders` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL COMMENT ‘下單用戶id‘, `number` varchar(32) NOT NULL COMMENT ‘訂單號‘, `createtime` datetime NOT NULL COMMENT ‘創建訂單時間‘, `note` varchar(100) DEFAULT NULL COMMENT ‘備註‘, PRIMARY KEY (`id`), KEY `FK_orders_1` (`user_id`), CONSTRAINT `FK_orders_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; insert into `orders`(`id`,`user_id`,`number`,`createtime`,`note`) values (3,1,‘1000010‘,‘2015-02-04 13:22:35‘,NULL),(4,1,‘1000011‘,‘2015-02-03 13:22:41‘,NULL),(5,10,‘1000012‘,‘2015-02-12 16:13:23‘,NULL); /*Table structure for table `user` */ DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL COMMENT ‘用戶名稱‘, `birthday` date DEFAULT NULL COMMENT ‘生日‘, `sex` char(1) DEFAULT NULL COMMENT ‘性別‘, `address` varchar(256) DEFAULT NULL COMMENT ‘地址‘, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8; insert into `user`(`id`,`username`,`birthday`,`sex`,`address`) values (1,‘王五‘,NULL,‘2‘,NULL),(10,‘張三‘,‘2014-07-10‘,‘1‘,‘北京市‘),(16,‘張小明‘,NULL,‘1‘,‘河南鄭州‘),(22,‘陳小明‘,NULL,‘1‘,‘河南鄭州‘),(24,‘張三豐‘,NULL,‘1‘,‘河南鄭州‘),(25,‘陳小明‘,NULL,‘1‘,‘河南鄭州‘),(26,‘王五‘,NULL,NULL,NULL); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
建表成功之後數據庫如圖所示:
java的環境是jdk1.7,eclipse使用mars2,spring使用3.2的版本。spring3.2所需要的jar包如圖所示:
至此,所需要的軟件和環境都準備完畢。
--------------------------------------------------------------------------------------------------------我是華麗的分割線------------------------------------------------------------------------------------------
開始正式開發第一個springmvc的程序。在eclipse搭建項目如下所示:
SpringMVC入門學習案例筆記