封面圖html
歡迎點擊上方藍色字體『 Bella的技術輪子 』
Easycode是idea的一個插件,能夠直接對數據的表生成entity,controller,service,dao,mapper,無需任何編碼,簡單而強大。vue
1. 安裝(EasyCode)
我這裏的話是已經裝好了。java
建議你們在安裝一個插件,叫作Lombok。
Lombok能經過註解的方式,在編譯時自動爲屬性生成構造器、getter/setter、equals、hashcode、toString方法。出現的神奇就是在源碼中沒有getter和setter方法,可是在編譯生成的字節碼文件中有getter和setter方法。
2. 創建數據庫
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`username` varchar(20) DEFAULT NULL,
`sex` varchar(6) DEFAULT NULL,
`birthday` date DEFAULT NULL,
`address` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET FOREIGN_KEY_CHECKS = 1;
3. 在IDEA配置鏈接數據庫
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
4. 開始生成代碼
在這個裏面找到你想生成的表,而後右鍵,就會出現以下所示的截圖。mysql
點擊1所示的位置,選擇你要將生成的代碼放入哪一個文件夾中,選擇完之後點擊OK便可。web
勾選你須要生成的代碼,點擊OK。spring
這樣的話就完成了代碼的生成了,生成的代碼以下圖所示:sql
5. pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--熱部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 這個須要爲 true 熱部署纔有效 -->
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!--阿里巴巴鏈接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.9</version>
</dependency>
6. Application.yml
server:
port: 8089
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=UTF-8
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:/mapper/*Dao.xml
typeAliasesPackage: com.vue.demo.entity
7. 啓動項目
在啓動項目以前,咱們須要先修改兩個地方。數據庫
在dao層加上@mapper註解微信
在啓動類裏面加上@MapperScan("com.vue.demo.dao")註解。mybatis
啓動項目
測試一下
做者:HeloWxl
連接:https://www.jianshu.com/p/e4192d7c6844
-END-
更多精彩文章
2.CPU Cache&Cache Line 與你寫的代碼之間到底是怎樣的關係呢?
5.Redis用過嗎?用過。那講一講跳躍表Skip list吧
若是你喜歡本文
請長按二維碼,關注 Bella的技術輪子
轉發至 朋友圈,是對我最大的支持
喜歡就點個在看吧
本文分享自微信公衆號 - Bella的技術輪子(wheel_of_bella)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。