项目结构
controller层
service层
pojo层
dao层
test 层
GeneratorSqlmap是mybatis逆向工程的main入口,能让你减少写sql的好帮手
util层
mail发送邮件
RandomString随机字符串用来做验证码的
resource层
mapper存放dao接口的mapper.xml配置文件
全局文件(就这么叫吧,我也不知道怎么叫)
逆向工程的配置文件
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>marketManage</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>marketManage Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<!-- springmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<!-- spring核心包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<!-- spring-mybatis整合包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- mybatis相关包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.3.RELEASE</version>
</dependency>
<!-- 导入mysql连接 -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.48</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.10</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
这博客编辑器真的是有问题,复制大段代码的时候时不时抽筋,害的我一行行复制的。这件事得记在小本本上,【滑稽】。
数据操作
数据库创库,表,数据输入
create database marketManager;
#管理员表
CREATE TABLE `marketmanager`.`managers` (
`mId` INT NOT NULL AUTO_INCREMENT,
`pass` VARCHAR(45) NOT NULL,
`mName` VARCHAR(45) NULL,
`mEmail` VARCHAR(45) NULL,
`mSex` VARCHAR(45) NULL,
`mPhone` VARCHAR(45) NULL,
PRIMARY KEY (`mId`));
##雇员表
CREATE TABLE `marketmanager`.`employeer` (
`eId` INT NOT NULL AUTO_INCREMENT,
`eName` VARCHAR(45) NULL,
`epass` VARCHAR(45) NULL,
`eSex` VARCHAR(45) NULL,
`eEmail` VARCHAR(45) NULL,
`ePhone` VARCHAR(45) NULL,
PRIMARY KEY (`eId`));
##会员表
CREATE TABLE `marketmanager`.`user`(
`uId` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`uId`),
`uName` VARCHAR(45) NULL,
`upass` VARCHAR(45) NULL,
`uRegister` Date
);
##仓库管理员
CREATE TABLE `marketmanager`.`store` (
`stoId` INT NOT NULL AUTO_INCREMENT,
`pass` VARCHAR(45) NOT NULL,
`stoName` VARCHAR(45) NULL,
`stoEmail` VARCHAR(45) NULL,
`stotSex` VARCHAR(45) NULL,
`stoPhone` VARCHAR(45) NULL,
PRIMARY KEY (`stoId`));
##商品表
CREATE TABLE `marketmanager`.`goods` (
`gId` INT NOT NULL AUTO_INCREMENT,
primary key(`gId`),
`gName` VARCHAR(45) NULL,
`gType` VARCHAR(45) NULL
);
##销售表
create table `marketmanager`.`transaction`(
`tId` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`tId`),
`gId` INT,
`eId` INT,
`buyDay` date,
`num` int,
`price` double
);
##供货商表
create table `marketmanager`.`supplier`(
`sId` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`sId`),
`sName` VARCHAR(45) NULL,
`sAddress` VARCHAR(45) NULL,
`sPhone` VARCHAR(45) NULL
);
##进货表
create table `marketmanager`.`stock`(
`stId` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`stId`),
`gId` INT,
`sId` INT,
`num` int
);
##插入managers表
insert into managers(mId,pass,mName,mEmail,mSex,mPhone) values(1,'123','lst','18917183336@163.com','男','18917183336');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf01','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf2','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf3','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf4','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf5','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf6','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf7','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf8','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf9','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf11','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf12','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf13','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf14','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf15','10001@163.com','男','10001');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('123','lhf','1536484524@163.com','女','13992236542');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('456','wzl','3652148526@163.com','男','13554266875');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('789','wlv','1522451250@163.com','女','13120512264');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('147','lyx','1236625241@163.com','女','18795826548');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('258','ztt','5126664525@163.com','女','15098403502');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('369','zy','1522684952@163.com','男','13352644859');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('951','wyw','1555223648@163.com','女','18749992635');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('753','hdx','4485469271@163.com','男','18993336528');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('157','cyr','1122368452@163.com','男','15996235426');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('359','znx','9957468215@163.com','男','15230500264');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('759','zwy','3265218265@163.com','女','15236442582');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('957','htl','1239852482@163.com','男','12365215251');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('153','xyy','5264815249@163.com','女','18995624523');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('351','els','6521834972@163.com','女','18336524152');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('681','fxq','6521843917@163.com','男','13552648726');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('sjx','龙傲天','wojiushilon@163.com','女','18993332541');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('sal','美羊羊','myylovexyy@163.com','女','18745026523');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('xla','红太狼','woaipingdiguo@163.com','女','14523679999');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('xal','纪晓岚','kanwotiechit@163.com','男','18888888888');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('ihy','诸葛亮','wojiushiche@163.com','男','13993321547');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('loy','皇太后','cixishiwo@163.com','女','13998245426');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('otg','杀马特','welcome@163.com','男','18332697458');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('inl','陆涛韬','woshiguanli@163.com','男','19332687458');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('ccl','张雅雅','woaizhangya@163.com','女','15268999426');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('och','余杭逍','laibaoyan@163.com','男','18332452215');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('qiy','派大星','haimianbaobao@163.com','男','1523652415');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('dhc','小程序','wozaiweixin@163.com','男','15236254128');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('dlc','宁荣荣','qibaoyongsheng@163.com','女','19332826485');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('tyd','黄晓明','anglybaby@163.com','男','18221542673');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('sot','曹郁睿','woshizhainan@163.com','女','18993326425');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('sax521','阿萨姆','asamu@163.com','男','12365241526');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('xki541','冰红茶','binghongcha@163.com','男','13926412521');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('wcg624','苦力怕','10kuliba@163.com','女','13526412582');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('swb129','手残党','wojiushia@163.com','男','18546924521');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('krv54','可可粉','haohedekafei@163.com','女','19644215215');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('wog597','蔡徐坤','jinitaimei@163.com','女','19562340512');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('ogj524','甘家堡','totoday@163.com','女','15423625412');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('ojv452','不带你','hellowword@163.com','男','13252415264');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('csa364','哦测试','ruangongzhuany@163.com','男','13526425552');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('wol652','古墓丽影','gumuliying@163.com','女','19888542625');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('cso954','刺客信条','cikexingtiao@163.com','男','18632542521');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('kyv152','阿里巴巴','alibaba@163.com','男','13665421524');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('our215','含辛茹苦','hanxingruku@163.com','男','18996526325');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('dlo957','苦不堪言','kubukanyan@163.com','女','18232521452');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('lkb963','言出必行','yanchubixing@163.com','男','13526245214');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('bsm328','行为举止','xingweijuzhi@163.com','男','19854252362');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('vfu957','指鹿为马','zhiluweima@163.com','女','12365241528');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('vjr652','马到成功','madaochenggong@163.com','女','18542635214');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('vfo652','功成名就','gongcehngmingjiu@163.com','女','175425125236');
insert into managers(pass,mName,mEmail,mSex,mPhone) values('eyc518','就事论事','zhongyuwanle163.com','男','12652345216');
##插入employeer表
repair table employeer;
insert into employeer(eId,eName,epass,eSex,eEmail,ePhone)values(1,'ccc','1234','男','18917183336@163.com','18917183336');
insert into employeer(eName,epass,eSex,eEmail,ePhone)values('wyh','1234','男','13214303@163.com','13214303');
##插入store
insert into store(stoId,pass,stoName,stoEmail,stotSex,stoPhone)values(1,'1111','jry','18917183336@163.com','男',18917183336);
insert into store(pass,stoName,stoEmail,stotSex,stoPhone)values('1111','yjq','18917183336@163.com','男',18917183336);
##插入goods表
insert into goods(gId,gType,gName) values(1,'书籍','钢铁是怎么炼成的?');
insert into goods(gType,gName) values('电子产品','电脑');
##插入supplier表
insert into supplier(sId,sName,sAddress,sPhone) values(1,'神州电脑有限公司','随便写路123号','18917183336');
insert into supplier(sName,sAddress,sPhone) values('台湾华硕电脑有限公司','随便写路124号','100011000');
##插入stock表
insert into stock(stId,gid,sId,num) values(1,2,1,123);
insert into stock(gid,sId,num) values(2,2,123);
在本系统中实际只使用了employeer,store,managers,其他的没时间写了,反正功能实现,其他的就是复制改名字
jdbc.properties
driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/marketManager?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
user=root
password=root
如果你是mysql8.0以上
driverclass改成com.mysql.cj.jdbc.Driver
generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/marketManager?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true" userId="root"
password="root">
</jdbcConnection>
<!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
userId="yycg"
password="yycg">
</jdbcConnection> -->
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:生成PO类的位置 -->
<javaModelGenerator targetPackage="com.market.pojo"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="mapper"
targetProject=".\src\main\resources">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.market.dao"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定数据库表 -->
<table tableName="employeer"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<!--
<table tableName="goods"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="managers"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="stock"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="supplier"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="transaction"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
-->
<table tableName="store"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<!-- 有些表的字段需要指定java类型
<table schema="" tableName="cst_customer">
<columnOverride column="cust_id" javaType="Long" />
</table> -->
</context>
</generatorConfiguration>
mybatis逆向工程生成的main
package com.market.test;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
public class GeneratorSqlmap {
public void generator() throws Exception{
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
//指定 逆向工程配置文件
File configFile = new File("generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
}
// public static void main(String[] args) throws Exception {
// try {
// GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
// generatorSqlmap.generator();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
}
用的时候把注释去了,网站写完了可以把逆向工程删了
好了数据模块解决了
整合的看那个王雪亮博客,不想复制黏贴代码了,一行行太繁了。
接下来请看我的下一个博客