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ù)庫訪問層") @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}; /** * 分頁查詢所有數(shù)據(jù) * * @return 所有數(shù)據(jù) */ @GetMapping public Object selectList() { return null; } /** * 通過主鍵查詢單條數(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)文章
java GUI實(shí)現(xiàn)ATM機(jī)系統(tǒng)(3.0版)
這篇文章主要為大家詳細(xì)介紹了java GUI實(shí)現(xiàn)ATM機(jī)系統(tǒng)(3.0版),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03SpringBoot數(shù)據(jù)訪問自定義使用Druid數(shù)據(jù)源的方法
本文記錄Druid數(shù)據(jù)源的使用,自定義實(shí)現(xiàn)Drud的功能、監(jiān)控頁、登錄、統(tǒng)計(jì)等。對(duì)SpringBoot數(shù)據(jù)訪問使用Druid數(shù)據(jù)源的相關(guān)知識(shí)感興趣額朋友一起看看吧2021-08-08Java實(shí)現(xiàn)序列化與反序列化的簡單示例
序列化與反序列化是指Java對(duì)象與字節(jié)序列的相互轉(zhuǎn)換,一般在保存或傳輸字節(jié)序列的時(shí)候會(huì)用到,下面有兩個(gè)Java實(shí)現(xiàn)序列化與反序列化的簡單示例,不過還是先來看看序列和反序列化的具體概念:2016-05-05SpringBoot工程搭建打包、啟動(dòng)jar包和war包的教程圖文詳解
這篇文章主要介紹了SpringBoot工程搭建打包、啟動(dòng)jar包和war包的教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09