首页 > 编程语言 > 详细

SpringMVC入门学习案例笔记

时间:2018-04-07 23:47:58      阅读:301      评论:0      收藏:0      [点我收藏+]

一、数据库环境用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`;

SET FOREIGN_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入门学习案例笔记

原文:https://www.cnblogs.com/1102whw/p/8735278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!