EasyCode整合mybatis-plus的配置詳解
這篇文章不教你如何安裝和使用EasyCode,只是貼出可以使用的配置。
具體EasyCode的使用可以查看其它的文章。
entity
##導(dǎo)入宏定義
$!{define.vm}
##保存文件(宏定義)
#save("/entity", ".java")
##包路徑(宏定義)
#setPackageSuffix("entity")
##自動(dòng)導(dǎo)入包(全局變量)
$!{autoImport.vm}
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
##表注釋(宏定義)
#tableComment("表實(shí)體類")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("$!{tableInfo.obj.name}")
public class $!{tableInfo.name} {
#foreach($column in $tableInfo.pkColumn)
#if(${column.comment})//${column.comment}#end
@TableId
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.otherColumn)
#if(${column.comment})//${column.comment}#end
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}mapper.java
##導(dǎo)入宏定義
$!{define.vm}
##設(shè)置表后綴(宏定義)
#setTableSuffix("Mapper")
##保存文件(宏定義)
#save("/mapper", "Mapper.java")
##包路徑(宏定義)
#setPackageSuffix("mapper")
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
##表注釋(宏定義)
#tableComment("表數(shù)據(jù)庫(kù)訪問(wèn)層")
@Mapper
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {
}mapper.xml
##引入mybatis支持
$!mybatisSupport
##設(shè)置保存名稱與保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
##拿到主鍵
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
<?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="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">
<!-- 結(jié)果集 -->
<resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
</resultMap>
<!-- 基本字段 -->
<sql id="Base_Column_List">
#allSqlColumn()
</sql>
</mapper>
service
##導(dǎo)入宏定義
$!{define.vm}
##設(shè)置表后綴(宏定義)
#setTableSuffix("Service")
##保存文件(宏定義)
#save("/service", "Service.java")
##包路徑(宏定義)
#setPackageSuffix("service")
import com.baomidou.mybatisplus.extension.service.IService;
##表注釋(宏定義)
#tableComment("表服務(wù)接口")
public interface $!{tableName} extends IService<$!tableInfo.name> {
}serviceImpl
##導(dǎo)入宏定義
$!{define.vm}
##設(shè)置表后綴(宏定義)
#setTableSuffix("ServiceImpl")
##保存文件(宏定義)
#save("/service/Impl", "ServiceImpl.java")
##包路徑(宏定義)
#setPackageSuffix("service.Impl")
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
##表注釋(宏定義)
#tableComment("表服務(wù)實(shí)現(xiàn)類")
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
@Slf4j
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {
}
controller
##導(dǎo)入宏定義
$!{define.vm}
##設(shè)置表后綴(宏定義)
#setTableSuffix("Controller")
##保存文件(宏定義)
#save("/controller", "Controller.java")
##包路徑(宏定義)
#setPackageSuffix("controller")
##定義服務(wù)名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定義實(shí)體對(duì)象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
##表注釋(宏定義)
#tableComment("表控制層[不建議修改,如果有新增的方法,寫在子類中]")
public class $!{tableName} {
/**
* 服務(wù)對(duì)象
*/
@Autowired
$!{tableInfo.name}Service $!{serviceName};
/**
* 分頁(yè)查詢所有數(shù)據(jù)
*
* @return 所有數(shù)據(jù)
*/
@GetMapping
public Object selectList() {
return null;
}
/**
* 通過(guò)主鍵查詢單條數(shù)據(jù)
*
* @param id 主鍵
* @return 單條數(shù)據(jù)
*/
@GetMapping("/{id}")
public Object selectOne(@PathVariable Long id) {
return null;
}
/**
* 新增數(shù)據(jù)
*
* @param $!entityName 實(shí)體對(duì)象
* @return 新增結(jié)果
*/
@PostMapping
public Object insert(@RequestBody $!tableInfo.name $!entityName) {
return null;
}
/**
* 修改數(shù)據(jù)
*
* @param $!entityName 實(shí)體對(duì)象
* @return 修改結(jié)果
*/
@PutMapping
public Object update(@RequestBody $!tableInfo.name $!entityName) {
return null;
}
/**
* 單條/批量刪除數(shù)據(jù)
*
* @param idList 主鍵集合
* @return 刪除結(jié)果
*/
@DeleteMapping
public Object delete(@RequestParam("idList") List<Long> idList) {
return null;
}
}到此這篇關(guān)于EasyCode整合mybatis-plus的配置詳解的文章就介紹到這了,更多相關(guān)EasyCode整合mybatis-plus配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
springcloud整合到項(xiàng)目中無(wú)法啟動(dòng)報(bào)錯(cuò)Failed to start bean&n
這篇文章主要介紹了springcloud整合到項(xiàng)目中無(wú)法啟動(dòng)報(bào)錯(cuò)Failed to start bean 'eurekaAutoServiceRegistration'問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
Springboot整合JPA配置多數(shù)據(jù)源流程詳解
這篇文章主要介紹了Springboot整合JPA配置多數(shù)據(jù)源,JPA可以通過(guò)實(shí)體類生成數(shù)據(jù)庫(kù)的表,同時(shí)自帶很多增刪改查方法,大部分sql語(yǔ)句不需要我們自己寫,配置完成后直接調(diào)用方法即可,很方便2022-11-11
Java?GUI實(shí)現(xiàn)多個(gè)窗口切換效果
這篇文章主要為大家詳細(xì)介紹了Java?GUI實(shí)現(xiàn)多個(gè)窗口的切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
SpringSession 請(qǐng)求與響應(yīng)重寫的實(shí)現(xiàn)
這篇文章主要介紹了SpringSession 請(qǐng)求與響應(yīng)重寫的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11
springboot集成@Cacheable緩存亂碼的問(wèn)題解決
本文介紹了Springboot應(yīng)用中遇到的Redis緩存數(shù)據(jù)亂碼問(wèn)題及其解決方案,問(wèn)題出現(xiàn)在使用@Cacheable注解后,Redis中的value顯示為亂碼,下面就來(lái)詳細(xì)的介紹一下該問(wèn)題的解決,感興趣的可以了解一下2025-10-10
Spring實(shí)現(xiàn)定時(shí)任務(wù)的幾種方式總結(jié)
Spring Task 是 Spring 框架提供的一種任務(wù)調(diào)度和異步處理的解決方案,可以按照約定的時(shí)間自動(dòng)執(zhí)行某個(gè)代碼邏輯它可以幫助開發(fā)者在 Spring 應(yīng)用中輕松地實(shí)現(xiàn)定時(shí)任務(wù)、異步任務(wù)等功能,提高應(yīng)用的效率和可維護(hù)性,需要的朋友可以參考下本文2024-07-07

