自己建网站卖东西好卖吗,用手机怎样免费做网站,微信指数查询,深圳房价文章目录1. 安装(EasyCode)2. 建立数据库3. 在IDEA配置连接数据库4. 开始生成代码5. pom.xml6. Application.yml7. 启动项目8. 测试一下Easycode是idea的一个插件#xff0c;可以直接对数据的表生成entity,controller,service,dao,mapper,无需任何编码#xff0c;简单而强大。…
文章目录1. 安装(EasyCode)2. 建立数据库3. 在IDEA配置连接数据库4. 开始生成代码5. pom.xml6. Application.yml7. 启动项目8. 测试一下Easycode是idea的一个插件可以直接对数据的表生成entity,controller,service,dao,mapper,无需任何编码简单而强大。1. 安装(EasyCode) 我这里的话是已经那装好了。
建议大家在安装一个插件叫做Lombok。Lombok能通过注解的方式在编译时自动为属性生成构造器、getter/setter、equals、hashcode、toString方法。出现的神奇就是在源码中没有getter和setter方法但是在编译生成的字节码文件中有getter和setter方法。
2. 建立数据库
/*Navicat Premium Data TransferSource Server : 127.0.0.1Source Server Type : MySQLSource Server Version : 50721Source Host : 127.0.0.1:3306Source Schema : easycodeTarget Server Type : MySQLTarget Server Version : 50721File Encoding : 65001Date: 12/03/2020 11:10:21
*/SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS 0;-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS user;
CREATE TABLE user (id int(11) NOT NULL,username varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,sex varchar(6) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,birthday date NULL DEFAULT NULL,address varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,password varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,PRIMARY KEY (id) USING BTREE
) ENGINE InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT Dynamic;-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO user VALUES (1, 雨昕, 1, 2017-09-30, 郭家梨行, 123456);SET FOREIGN_KEY_CHECKS 1;
3. 在IDEA配置连接数据库
在这个之前新建一个Springboot项目这个应该是比较简单的。 建好SpringBoot项目之后如下图所示找到这个Database 然后填写数据库名字用户名密码。点击OK即可。这样的话IDEA连接数据库就完事了。
4. 开始生成代码
在这个里面找到你想生成的表然后右键就会出现如下所示的截面。 点击所示的位置选择你要将生成的代码放入哪个文件夹中选择完以后点击OK即可 生成后的效果图
5. pom.xml !--SpringMVC 组件--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!--Lombok 组件--dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency!--热部署--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdoptionaltrue/optional !-- 这个需要为 true 热部署才有效 --/dependency!--mybatis 组件--dependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion1.3.2/version/dependency!-- mysql 高版本8.x--dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.13/version/dependency!--阿里巴巴连接池--dependencygroupIdcom.alibaba/groupIdartifactIddruid/artifactIdversion1.0.9/version/dependency6. Application.yml
server:port: 80# Mysql数据库 适用于6.x及以上
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/easycode?autoReconnecttrueuseUnicodetruecharacterEncodingutf8zeroDateTimeBehaviorCONVERT_TO_NULLuseSSLfalseserverTimezoneCTTusername: rootpassword: rootfilters: wall,mergeStat
mybatis:mapper-locations: classpath:/mapper/*Dao.xmltypeAliasesPackage: com.gblfy.entity##5.x 版本使用下面的连接串
#spring:
# datasource:
# url: jdbc:mysql://127.0.0.1:3306/easycode?useUnicodetruecharacterEncodingUTF-8
# username: root
# password: root
# type: com.alibaba.druid.pool.DruidDataSource
# driver-class-name: com.mysql.jdbc.Driver7. 启动项目
在启动项目之前我们需要先修改两个地方。 在dao层加上mapper注解 在启动类里面加上MapperScan(“com.gblfy.dao”)注解。
8. 测试一下
http://localhost/user/selectOne?id1