您好,登錄后才能下訂單哦!
這篇文章主要介紹“easycode怎么配置成mybatis-plus模板”,在日常操作中,相信很多人在easycode怎么配置成mybatis-plus模板問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”easycode怎么配置成mybatis-plus模板”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
本文主要介紹了easycode配置成mybatis-plus模板的實(shí)現(xiàn)方法,分享給大家,具體如下:
entity.java
##導(dǎo)入宏定義 $!define ##保存文件(宏定義) #save("/entity", ".java") ##包路徑(宏定義) #setPackageSuffix("entity") ##自動(dòng)導(dǎo)入包(全局變量) $!autoImport import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.Date; ##表注釋(宏定義) #tableComment("表實(shí)體類") @Data @Builder @AllArgsConstructor @NoArgsConstructor @ApiModel("$!{tableInfo.comment}") public class $!{tableInfo.name} implements Serializable { private static final long serialVersionUID = $!tool.serial(); #foreach($column in $tableInfo.fullColumn) #if(${column.comment})/** * ${column.comment} */#end #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end #if($column.name.equals('id'))@TableId(type = IdType.AUTO)#end private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end }
dao.java
##導(dǎo)入宏定義 $!define ##設(shè)置表后綴(宏定義) #setTableSuffix("Mapper") ##保存文件(宏定義) #save("/mapper", "Mapper.java") ##包路徑(宏定義) #setPackageSuffix("mapper") import com.baomidou.mybatisplus.core.mapper.BaseMapper; import $!{tableInfo.savePackageName}.entity.$!tableInfo.name; ##表注釋(宏定義) #tableComment("表數(shù)據(jù)庫(kù)訪問層") public interface $!{tableName} extends BaseMapper<$!tableInfo.name> { }
server.java
##導(dǎo)入宏定義 $!define ##設(shè)置表后綴(宏定義) #setTableSuffix("Service") ##保存文件(宏定義) #save("/service", "Service.java") ##包路徑(宏定義) #setPackageSuffix("service") import com.baomidou.mybatisplus.extension.service.IService; import $!{tableInfo.savePackageName}.entity.$!tableInfo.name; ##表注釋(宏定義) #tableComment("表服務(wù)接口") public interface $!{tableName} extends IService<$!tableInfo.name> { }
serverImpl.java
##導(dǎo)入宏定義 $!define ##設(shè)置表后綴(宏定義) #setTableSuffix("ServiceImpl") ##保存文件(宏定義) #save("/service/impl", "ServiceImpl.java") ##包路徑(宏定義) #setPackageSuffix("service.impl") import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; ##表注釋(宏定義) #tableComment("表服務(wù)實(shí)現(xiàn)類") @Slf4j @Service public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service { }
controller.java
##導(dǎo)入宏定義 $!define ##設(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 io.swagger.annotations.ApiOperation; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.api.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.Serializable; import java.util.List; ##表注釋(宏定義) #tableComment("表控制層[不建議修改,如果有新增的方法,寫在子類中]") @RestController public class $!{tableName} { /** * 服務(wù)對(duì)象 */ @Autowired $!{tableInfo.name}Service $!{serviceName}; /** * 分頁(yè)查詢所有數(shù)據(jù) * * @param page 分頁(yè)對(duì)象 * @param $!entityName 查詢實(shí)體 * @return 所有數(shù)據(jù) */ @ApiOperation("分頁(yè)查詢所有數(shù)據(jù)") @GetMapping public R<IPage<$!tableInfo.name>> selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) { return R.ok ($!{serviceName}.page(page, new QueryWrapper<>($!entityName))); } /** * 通過主鍵查詢單條數(shù)據(jù) * * @param id 主鍵 * @return 單條數(shù)據(jù) */ @ApiOperation("通過主鍵查詢單條數(shù)據(jù)") @GetMapping("{id}") public R<$!tableInfo.name> selectOne(@PathVariable Serializable id) { return R.ok($!{serviceName}.getById(id)); } /** * 新增數(shù)據(jù) * * @param $!entityName 實(shí)體對(duì)象 * @return 新增結(jié)果 */ @ApiOperation("新增數(shù)據(jù)") @PostMapping public R<Long> insert(@RequestBody $!tableInfo.name $!entityName) { boolean rs = $!{serviceName}.save($!entityName); return R.ok(rs?$!{entityName}.getId():0); } /** * 修改數(shù)據(jù) * * @param $!entityName 實(shí)體對(duì)象 * @return 修改結(jié)果 */ @ApiOperation("修改數(shù)據(jù)") @PutMapping public R<Boolean> update(@RequestBody $!tableInfo.name $!entityName) { return R.ok($!{serviceName}.updateById($!entityName)); } /** * 單條/批量刪除數(shù)據(jù) * * @param idList 主鍵集合 * @return 刪除結(jié)果 */ @ApiOperation("單條/批量刪除數(shù)據(jù)") @DeleteMapping public R<Boolean> delete(@RequestParam("idList") List<Long> idList) { return R.ok($!{serviceName}.removeByIds(idList)); } }
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"> <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}BaseResultMap"> #foreach($column in $tableInfo.fullColumn) <result property="$!column.name" column="$!column.obj.name"/> #end </resultMap> </mapper>
修改簽名
到此,關(guān)于“easycode怎么配置成mybatis-plus模板”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。