ssm实战(二)建表、配置maven

上面说了大致各个角色功能和前端展示系统,现在就设计实体类及其对应的数据库的表,一共有11个实体类,分别是












public class Account {//系统账号,登陆用的
private Long accountId;
private String accountNumber;
private String accountPassword;
private Integer type;//0学生,1前台,2物资管理,3图书管理,4超级管理员,学生可以自己注册
private Date createTime;
private Date lastLoginTime;
private Integer enableStatus;//账号可用情况

根据这些信息在数据库建立相应的表,建表代码如下

CREATE TABLE `tb_area` (
  `area_id` int(2) NOT NULL AUTO_INCREMENT,
  `area_name` varchar(200) NOT NULL,
  `create_date` datetime DEFAULT NULL,
  `priority` int(2) NOT NULL DEFAULT '0',
  `last_edit_time` datetime DEFAULT NULL,
  `area_desc` varchar(1024) DEFAULT NULL,
  PRIMARY KEY (`area_id`),
  UNIQUE KEY `area_name` (`area_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

CREATE TABLE `tb_book` (
  `book_id` int(11) NOT NULL AUTO_INCREMENT,
  `book_name` varchar(256) NOT NULL,
  `book_desc` varchar(1024) DEFAULT NULL,
  `book_img` varchar(1024) DEFAULT NULL,
  `book_addr` varchar(1024) DEFAULT NULL,
  `priority` int(3) DEFAULT '0',
  `create_time` datetime DEFAULT NULL,
  `last_edit_time` datetime DEFAULT NULL,
  `enable_status` int(2) DEFAULT '0' COMMENT '上下架,审核',
  `book_category_id` int(11) DEFAULT NULL,
  `total_count` int(11) NOT NULL DEFAULT '0',
  `borrow_count` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`book_id`),
  KEY `fk_book_category_book` (`book_category_id`),
  CONSTRAINT `fk_book_category_book` FOREIGN KEY (`book_category_id`) REFERENCES `tb_book_category` (`book_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `tb_book_category` (
  `book_category_id` int(11) NOT NULL AUTO_INCREMENT,
  `book_category_name` varchar(100) DEFAULT NULL,
  `book_category_desc` varchar(1000) DEFAULT NULL,
  `book_category_img` varchar(2000) DEFAULT NULL,
  `priority` int(2) NOT NULL DEFAULT '0',
  `creat_time` datetime DEFAULT NULL,
  `last_edit_time` datetime DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  `area_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`book_category_id`),
  KEY `fk_book_category_self` (`parent_id`),
  KEY `fk_area_book` (`area_id`),
  CONSTRAINT `fk_area_book` FOREIGN KEY (`area_id`) REFERENCES `tb_area` (`area_id`),
  CONSTRAINT `fk_book_category_self` FOREIGN KEY (`parent_id`) REFERENCES `tb_book_category` (`book_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `tb_manager` (
  `manager_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) DEFAULT NULL,
  `profile_img` varchar(1024) DEFAULT NULL,
  `phone` varchar(100) DEFAULT NULL,
  `gender` varchar(2) DEFAULT NULL,
  `enable_status` int(2) DEFAULT '0',
  `manager_type` int(2) NOT NULL DEFAULT '1',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`manager_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `tb_notice` (
  `notice_id` int(11) NOT NULL AUTO_INCREMENT,
  `context` varchar(1024) DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  `last_edit_time` datetime DEFAULT NULL,
  `priority` int(2) DEFAULT NULL,
  `enable_status` int(2) NOT NULL DEFAULT '0' COMMENT '公告可用与否',
  PRIMARY KEY (`notice_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `tb_record` (
  `record_id` int(11) NOT NULL AUTO_INCREMENT,
  `record_desc` varchar(1024) NOT NULL,
  `create_time` datetime DEFAULT NULL,
  `student_id` int(11) DEFAULT NULL,
  `manager_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`record_id`),
  KEY `fk_record_student` (`student_id`),
  KEY `fk_record_manager` (`manager_id`),
  CONSTRAINT `fk_record_student` FOREIGN KEY (`student_id`) REFERENCES `tb_student` (`student_id`),
  CONSTRAINT `fk_record_manager` FOREIGN KEY (`manager_id`) REFERENCES `tb_manager` (`manager_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `tb_student` (
  `student_id` int(10) NOT NULL AUTO_INCREMENT,
  `student_name` varchar(32) DEFAULT NULL,
  `profile_img` varchar(1024) DEFAULT NULL,
  `gender` varchar(2) DEFAULT NULL,
  `enable_status` int(2) NOT NULL DEFAULT '0' COMMENT '是否可用',
  `create_time` datetime DEFAULT NULL,
  `last_edit_time` datetime DEFAULT NULL,
  `email` varchar(1024) DEFAULT NULL,
  `credit_score` int(3) DEFAULT NULL,
  PRIMARY KEY (`student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
 
 
CREATE TABLE `tb_operation_record` (
  `operation_record_id` int(11) NOT NULL AUTO_INCREMENT,
  `operation_desc` varchar(1024) DEFAULT NULL,
  `operator_id` int(11) NOT NULL,
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`operation_record_id`),
  KEY `fk_operator` (`operator_id`),
  CONSTRAINT `fk_operator` FOREIGN KEY (`operator_id`) REFERENCES `tb_manager` (`manager_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


CREATE TABLE `tb_material` (
  `material_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `total_count` int(11) NOT NULL,
  `create_date` datetime DEFAULT NULL,
  `last_edit_time` datetime DEFAULT NULL,
  PRIMARY KEY (`material_id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

CREATE TABLE `tb_area_material` (
  `material_area_info_id` int(11) NOT NULL AUTO_INCREMENT,
  `area_id` int(11) NOT NULL,
  `material_id` int(11) NOT NULL,
  `material_count` int(11) NOT NULL,
  `create_date` datetime DEFAULT NULL,
  `last_edit_time` datetime DEFAULT NULL,
  PRIMARY KEY (`material_area_info_id`),
  KEY `fk_area` (`area_id`),
  KEY `fk_material` (`material_id`),
  CONSTRAINT `fk_area` FOREIGN KEY (`area_id`) REFERENCES `tb_area` (`area_id`),
  CONSTRAINT `fk_material` FOREIGN KEY (`material_id`) REFERENCES `tb_material` (`material_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `tb_account` (
  `account_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_number` varchar(30) NOT NULL,
  `account_password` varchar(20) NOT NULL,
  `type` int(2) NOT NULL DEFAULT '0',
  `create_time` datetime DEFAULT NULL,
  `last_login_time` datetime DEFAULT NULL,
  `enable_status` int(2) NOT NULL DEFAULT '0',
  PRIMARY KEY (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8




建好表以后就继续构建maven项目:

在resources下新建两个文件夹存放mybatis的mapper文件和spring的配置文件


然后在webcontent文件夹下新建resources文件夹(存放js,css等资源)

然后构建项目基本目录


web用来存放控制器,service是业务逻辑层,dao是和数据持久层(与数据相关的操作),dto是弥补entity不足,比如entity返回一个列表,并且要返回一个标识是否成功,其实就是对实体类的进一步封装,enums是枚举类,interceptor是拦截器,用于权限校验,登陆等等,util是存放通用的工具类

接下来是引用jar包

要上maven公库去找到相应的jar包的坐标,最好选多人用的版本,最后配置到的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.gdut.imis2</groupId>
  <artifactId>library</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
   <properties>
		<spring.version>4.3.7.RELEASE</spring.version>
	</properties>
  
  <dependencies>
  <!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
 <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>
 <!-- Spring -->
		<!-- 1)包含Spring 框架基本的核心工具类。Spring 其它组件要都要使用到这个包里的类,是其它组件的基本核心 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 2)这个jar 文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean 以及进行Inversion of Control 
			/ Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI 支持,引入spring-core.jar 
			及spring-beans.jar 文件就可以了。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 3)这个jar 文件为Spring 核心提供了大量扩展。可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI 
			所需的全部类,instrumentation组件以及校验Validation 方面的相关类。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 4) 这个jar 文件包含对Spring 对JDBC 数据访问进行封装的所有类。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 5) 为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和编程式事务管理。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 6)Spring web 包含Web应用开发时,用到Spring框架时所需的核心类,包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 7)包含SpringMVC框架相关的所有类。 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- 8)Spring test 对JUNIT等测试框架的简单封装 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- servlet web -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>
		<!-- json解析 -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.5</version>
</dependency>
		<!-- spring-core需要用到 -->
<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.2.1</version>
</dependency>
		<!-- mybatis -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.1</version>
</dependency>
	<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.1</version>
</dependency>
	<!-- 数据库连接 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.38</version>
</dependency>
	<!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
			<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.2</version>
		</dependency>
 
 
  </dependencies>
  	<build>
		<finalName>libraray</finalName>
		<plugins>
			<plugin>
				<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF8</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>
  
</project>

自此,maven的配置结束

然后完善各层的配置。

猜你喜欢

转载自blog.csdn.net/weixin_37703281/article/details/81040578