在平日里代码的开发工作中,重复最多的还是对表的增删改查,很耗时,这就提起了目前项目的组件选型,用的是springboot+mybatis,写逻辑之前还要花几刻钟写增删改查的mapper,leader说就写几个xml吧不多,但是我想哭,看着这么多需求过来,宝宝哭着要下班呢。
以下代码为 伪代码 结构:
@Repository
public interface BasAuditNoticeMapper{
/**
*
* @param auditNoticeId
* @return
*/
BasAuditNotice selectById(@Param("auditNoticeId") Long auditNoticeId);
...
<mapper namespace="com.dtwave.dipper.dubhe.server.database.dao.table.BasAuditNoticeMapper">
<resultMap id="BaseResultMap" type="com.dtwave.dipper.dubhe.server.database.entity.table.BasAuditNotice">
<id column="audit_notice_id" property="auditNoticeId"/>
<result column="ctime" property="ctime"/>
<result column="mtime" property="mtime"/>
<result column="table_id" property="tableId"/>
<result column="field_id" property="fieldId"/>
</resultMap>
<sql id="BaseColumnList">
<trim suffix="" suffixOverrides=",">
audit_notice_id as auditNoticeId,
ctime as ctime,
mtime as mtime,
table_id as tableId,
field_id as fieldId
</trim>
</sql>
<!-- 根据ID查询 -->
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="BaseColumnList"/>
from bas_audit_notice
where audit_notice_id = #{auditNoticeId}
and invalid=0
</select>
@Data
public class BasAuditNotice {
/**
* 告警记录自增id
*/
private Long auditNoticeId;
/**
* 创建时间
*/
private Date ctime;
/**
* 修改时间
*/
private Date mtime;
/**
* 任务ID
*/
private Long taskId;
...
}
mybatis配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://${spring.datasource.url}"/>
<property name="username" value="${spring.datasource.username}"/>
<property name="password" value="${spring.datasource.password}"/>
<property name="filters" value="config,stat"/>
<property name="connectionProperties" value="config.decrypt=false"/>
<property name="initialSize" value="10"/>
<property name="minIdle" value="1"/>
<property name="maxActive" value="50"/>
<property name="maxWait" value="60000"/>
<property name="timeBetweenEvi