尚筹网项目系列笔记01[转尚硅谷https://www.bilibili.com/video/BV1bE411T7oZ]

尚筹网后台项目环境搭建01-创建工程目录

1 环境搭建总体目标

总技术架构

2 创建工程

2.1 项目架构图

项目架构

2.2 工程创建

namegroupIdartifactIdpackaging
atcrowdfunding01-admin-parentcom.atguigu.crowdatcrowdfunding01-admin-parentpom
atcrowdfunding02-admin-webuicom.atguigu.crowdatcrowdfunding02-admin-webuiwar
atcrowdfunding03-admin-componentcom.atguigu.crowdatcrowdfunding03-admin-componentjar
atcrowdfunding04-admin-entitycom.atguigu.crowdatcrowdfunding04-admin-entityjar
atcrowdfunding05-common-utilcom.atguigu.crowdatcrowdfunding05-common-utiljar
atcrowdfunding06-common-reversecom.atguigu.crowdatcrowdfunding06-common-reversejar

2.3 Maven工程和Maven模块的介绍

创建工程时参与继承、聚合的工程以“Maven module”的方式创建,继承和聚合可以自动配置出来。

创建过程:

  1. 创建Java Working Set
    在这里插入图片描述
    创建Java Working Set
  2. 创建parent项目(Maven project)
    在这里插入图片描述
    在这里插入图片描述
  3. 创建webui、component、entity项目(Maven module)
    在这里插入图片描述
    在这里插入图片描述

注意打包形式: webui项目是war包,其他的都是jar包

  1. 创建util、reverse项目(Maven project)
    在这里插入图片描述

在这里插入图片描述

2.4 设置模块间的依赖

webui依赖component
在这里插入图片描述

在这里插入图片描述
component依赖entity、util
在这里插入图片描述

3 引入所需的jar包

通过parent项目的pom.xml来控制jar包的版本

<properties>
	<!-- 声明属性,对 Spring 的版本进行统一管理 -->
	<atguigu.spring.version>4.3.20.RELEASE</atguigu.spring.version>

	<!-- 声明属性,对 SpringSecurity 的版本进行统一管理 -->
	<atguigu.spring.security.version>4.2.10.RELEASE</atguigu.spring.security.version>
</properties>
<dependencyManagement>
	<dependencies>
		<!-- Spring依赖 -->
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>${atguigu.spring.version}</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${atguigu.spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${atguigu.spring.version}</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.9.2</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/cglib/cglib -->
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>2.2</version>
		</dependency>

		<!-- 数据库依赖 -->
		<!-- MySQL驱动 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.3</version>
		</dependency>

		<!-- 数据源 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.31</version>
		</dependency>

		<!-- MyBatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.2.8</version>
		</dependency>

		<!-- MyBatis与Spring整合 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.2</version>
		</dependency>

		<!-- MyBatis分页插件 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
			<version>4.0.0</version>
		</dependency>

		<!-- 日志 -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.7</version>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.2.3</version>
		</dependency>

		<!-- 其他日志框架的中间转换包 -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<version>1.7.25</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jul-to-slf4j</artifactId>
			<version>1.7.25</version>
		</dependency>

		<!-- Spring进行JSON数据转换依赖 -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.9.8</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.9.8</version>
		</dependency>

		<!-- JSTL标签库 -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

		<!-- junit测试 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>

		<!-- 引入Servlet容器中相关依赖 -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>

		<!-- JSP页面使用的依赖 -->
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1.3-b06</version>
			<scope>provided</scope>
		</dependency>

		<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.8.5</version>
		</dependency>
	</dependencies>
</dependencyManagement>

4 准备数据库环境

建库和建表语句

CREATE DATABASE `project_crowd` CHARACTER SET utf8;
use project_crowd; 
drop table if exists t_admin; 
create table t_admin ( 
	id int not null auto_increment, # 主键 
	login_acct varchar(255) not null, # 登录账号 
	user_pswd char(32) not null, # 登录密码 
	user_name varchar(255) not null, # 昵称 
	email varchar(255) not null, # 邮件地址 
	create_time char(19), # 创建时间 
	primary key (id) 
);

5 准备Mybatis逆向工程环境

  1. 介绍
    逆向工程: 为简便程序员的开发,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需要的代码(XxxMapper.java、XxxMapper.xml、pojo类),可以让程序员将更多的精力放在繁杂的业务逻辑上。
  2. 环境准备
    reverse工程的pom.xml引入Mybatis逆向工程所需依赖(reverse工程是专门用来执行生成逆向工程的)
<!-- 依赖 MyBatis 核心包 --> 
<dependencies> 
	<dependency> 
		<groupId>org.mybatis</groupId> 
		<artifactId>mybatis</artifactId> 
		<version>3.2.8</version> 
	</dependency> 
</dependencies>
<!-- 控制Maven在构建过程中相关配置 -->
<build>
	<!-- 构建过程中用到的插件 -->
	<plugins>
		<!-- 具体插件,逆向工程的操作是以构建过程中插件形式出现的 -->
		<plugin>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-maven-plugin</artifactId>
			<version>1.3.0</version>
			<!-- 插件的依赖 -->
			<dependencies>
				<!-- 逆向工程的核心依赖 -->
				<dependency>
					<groupId>org.mybatis.generator</groupId>
					<artifactId>mybatis-generator-core</artifactId>
					<version>1.3.2</version>
				</dependency>
				<!-- 数据库连接池 -->
				<dependency>
					<groupId>com.mchange</groupId>
					<artifactId>c3p0</artifactId>
					<version>0.9.2</version>
				</dependency>
				<!-- MySQL驱动 -->
				<dependency>
					<groupId>mysql</groupId>
					<artifactId>mysql-connector-java</artifactId>
					<version>5.1.8</version>
				</dependency>
			</dependencies>
		</plugin>
	</plugins>
</build>
  1. 创建逆向工程所需的generatorConfig.xml
    该配置文件用来配置数据库(连接)信息、指定的文件生成路径、以及要逆向的数据库表
    在这里插入图片描述
    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>
	<!-- mybatis-generator:generate -->
	<context id="atguiguTables" targetRuntime="MyBatis3">
		<commentGenerator>
			<!-- 是否去除自动生成的注释 true:是;false:否 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>

		<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
		<jdbcConnection 
			driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/project_crowd" 
			userId="root"
			password="密码">
		</jdbcConnection>

		<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 
			和 NUMERIC 类型解析为java.math.BigDecimal -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- targetProject:生成Entity类的路径 -->
		<javaModelGenerator targetProject=".\src\main\java"
			targetPackage="com.atguigu.crowd.entity">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
			<!-- 从数据库返回的值被清理前后的空格 -->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!-- targetProject:XxxMapper.xml映射文件生成的路径 -->
		<sqlMapGenerator targetProject=".\src\main\java"
			targetPackage="com.atguigu.crowd.mapper">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>

		<!-- targetPackage:Mapper接口生成的位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetProject=".\src\main\java"
			targetPackage="com.atguigu.crowd.mapper">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>

		<!-- 数据库表名字和我们的entity类对应的映射指定 -->
		<table tableName="t_admin" domainObjectName="Admin" />

	</context>
</generatorConfiguration>

6 整个工程的目录结构

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值