結緣
之前瞭解mybatis的時候,發現mybatis-generator好用,可以把數據庫的表通過代碼生成entity,dao和mapper,其中entity裏的字段和表一一對應。dao是一系列方法的接口類,mapper是dao的xml格式的實現,裏面主要是sql語句,如果想顯擺一下sql高超的技術,就在mapper的xml裏面多多聯繫吧,😄
然而翻了許多文章,發現mybatis-generator能把mysql一個數據庫的所有的表正向和逆向的映射或創建,但是oracle,卻只能一個一個創建。,而且還是代碼方式,一直想有個web項目能批量連接一個oracle庫之後批量生成entity,dao和mapper,
mybatis-generator的網頁版
終於,一個機會出現了,在這篇文章中《從零到百億互聯網金融架構發展史》瞭解了關於一個開源項目《generator-web》,學習之
本地跑起來generator-web
IDE:IDEA
JDK:1.7.0_06
Tomcat:8.0.33
其他細節參考:idea配置tomcat啓動(Maven項目)
https://blog.csdn.net/dulinanaaa/article/details/88633539
跑起來generator-web
跑起來之後長這樣
輸入一個表t_message
下載解壓之後
DAO
package com.burns.gunslite.dao;
import com.burns.gunslite.entity.MessageEntity;
public interface MessageDao {
public int deleteByPrimaryKey(Long id);
public int insertSelective(MessageEntity record);
public MessageEntity selectByPrimaryKey(Long id);
public int updateByPrimaryKeySelective(MessageEntity record);
}
entity
package com.burns.gunslite.entity;
import java.util.Date;
/**
* @ClassName MessageEntity
* @Description 歷史消息
* @author 35725
* @date 2020-02-07 14:48:52
* @version 1.0
*/
public class MessageEntity {
private Long id;
//創建人
private Long create_by;
//創建時間/註冊時間
private Date create_time;
//最後更新人
private Long modify_by;
//最後更新時間
private Date modify_time;
//消息內容
private String content;
//接收者
private String receiver;
//消息類型,0:初始,1:成功,2:失敗
private String state;
//模板編碼
private String tpl_code;
//消息類型,0:短信,1:郵件
private String type;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCreate_by() {
return create_by;
}
public void setCreate_by(Long create_by) {
this.create_by = create_by;
}
public Date getCreate_time() {
return create_time;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Long getModify_by() {
return modify_by;
}
public void setModify_by(Long modify_by) {
this.modify_by = modify_by;
}
public Date getModify_time() {
return modify_time;
}
public void setModify_time(Date modify_time) {
this.modify_time = modify_time;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getTpl_code() {
return tpl_code;
}
public void setTpl_code(String tpl_code) {
this.tpl_code = tpl_code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
mapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.burns.gunslite.dao.MessageDao" >
<resultMap id="BaseResultMap" type="com.burns.gunslite.entity.MessageEntity" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="create_by" property="create_by" jdbcType="BIGINT" />
<result column="create_time" property="create_time" jdbcType="TIMESTAMP" />
<result column="modify_by" property="modify_by" jdbcType="BIGINT" />
<result column="modify_time" property="modify_time" jdbcType="TIMESTAMP" />
<result column="content" property="content" jdbcType="LONGVARCHAR" />
<result column="receiver" property="receiver" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="VARCHAR" />
<result column="tpl_code" property="tpl_code" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, create_by, create_time, modify_by, modify_time, content, receiver, state, tpl_code,
type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from t_message
where id = #{id,jdbcType=BIGINT}
</select>
<insert id="insertSelective" parameterType="com.burns.gunslite.entity.MessageEntity" >
insert into t_message
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="create_by != null" >
create_by,
</if>
<if test="create_time != null" >
create_time,
</if>
<if test="modify_by != null" >
modify_by,
</if>
<if test="modify_time != null" >
modify_time,
</if>
<if test="content != null" >
content,
</if>
<if test="receiver != null" >
receiver,
</if>
<if test="state != null" >
state,
</if>
<if test="tpl_code != null" >
tpl_code,
</if>
<if test="type != null" >
type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="create_by != null" >
#{create_by,jdbcType=BIGINT},
</if>
<if test="create_time != null" >
#{create_time,jdbcType=TIMESTAMP},
</if>
<if test="modify_by != null" >
#{modify_by,jdbcType=BIGINT},
</if>
<if test="modify_time != null" >
#{modify_time,jdbcType=TIMESTAMP},
</if>
<if test="content != null" >
#{content,jdbcType=LONGVARCHAR},
</if>
<if test="receiver != null" >
#{receiver,jdbcType=VARCHAR},
</if>
<if test="state != null" >
#{state,jdbcType=VARCHAR},
</if>
<if test="tpl_code != null" >
#{tpl_code,jdbcType=VARCHAR},
</if>
<if test="type != null" >
#{type,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.burns.gunslite.entity.MessageEntity" >
update t_message
<set >
<if test="create_by != null" >
create_by = #{create_by,jdbcType=BIGINT},
</if>
<if test="create_time != null" >
create_time = #{create_time,jdbcType=TIMESTAMP},
</if>
<if test="modify_by != null" >
modify_by = #{modify_by,jdbcType=BIGINT},
</if>
<if test="modify_time != null" >
modify_time = #{modify_time,jdbcType=TIMESTAMP},
</if>
<if test="content != null" >
content = #{content,jdbcType=LONGVARCHAR},
</if>
<if test="receiver != null" >
receiver = #{receiver,jdbcType=VARCHAR},
</if>
<if test="state != null" >
state = #{state,jdbcType=VARCHAR},
</if>
<if test="tpl_code != null" >
tpl_code = #{tpl_code,jdbcType=VARCHAR},
</if>
<if test="type != null" >
type = #{type,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from t_message
where id = #{id,jdbcType=BIGINT}
</delete>
</mapper>
不過需要多個表下載是,需要手動添加,此處可以顯示多個表,然後根據需要可以刪除
後面會學習其中的代碼,並嘗試輸出一個 基於oracle版本的web,暫定mybatis-generator-web-oracle,哈哈,好長。。。。。。。。。。。