可使用EasyCode插件生成Controller,Service,Mapper.java, 使用MybatisX插件生成entity和mapper.xml
controller.java.vm
| ##导入宏定义 |
| $!{define.vm} |
| |
| ##设置表后缀(宏定义) |
| #setTableSuffix("Controller") |
| |
| ##保存文件(宏定义) |
| #save("/controller", "Controller.java") |
| |
| ##包路径(宏定义) |
| #setPackageSuffix("controller") |
| |
| ##定义服务名 |
| #set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) |
| |
| ##定义实体对象名 |
| #set($entityName = $!tool.firstLowerCase($!tableInfo.name)) |
| |
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| import com.baomidou.mybatisplus.extension.api.ApiController; |
| import com.baomidou.mybatisplus.extension.api.R; |
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; |
| import org.springframework.web.bind.annotation.*; |
| |
| import javax.annotation.Resource; |
| import java.io.Serializable; |
| import java.util.List; |
| |
| ##表注释(宏定义) |
| #tableComment("表控制层") |
| @RestController |
| @RequestMapping("$!tool.firstLowerCase($!tableInfo.name)") |
| public class $!{tableName} extends ApiController { |
| |
| @Autowired |
| private $!{tableInfo.name}Service $!{serviceName}; |
| |
| |
| |
| |
| |
| |
| |
| |
| @GetMapping |
| public R selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) { |
| return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName))); |
| } |
| |
| |
| |
| |
| |
| |
| |
| @GetMapping("{id}") |
| public R selectOne(@PathVariable Serializable id) { |
| return success(this.$!{serviceName}.getById(id)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| @PostMapping |
| public R insert(@RequestBody $!tableInfo.name $!entityName) { |
| return success(this.$!{serviceName}.save($!entityName)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| @PutMapping |
| public R update(@RequestBody $!tableInfo.name $!entityName) { |
| return success(this.$!{serviceName}.updateById($!entityName)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| @DeleteMapping |
| public R delete(@RequestParam("idList") List<Long> idList) { |
| return success(this.$!{serviceName}.removeByIds(idList)); |
| } |
| } |
| |
controller-empty.java.vm
| # |
| $!{define.vm} |
| |
| # |
| #setTableSuffix("Controller") |
| |
| # |
| #save("/controller", "Controller.java") |
| |
| # |
| #setPackageSuffix("controller") |
| |
| # |
| #set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) |
| |
| # |
| #set($entityName = $!tool.firstLowerCase($!tableInfo.name)) |
| |
| import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; |
| import org.springframework.web.bind.annotation.*; |
| |
| # |
| #tableComment("表控制层") |
| @RestController |
| @RequestMapping("") |
| public class $!{tableName} { |
| |
| @Autowired |
| private $!{tableInfo.name}Service $!{serviceName}; |
| |
| |
| } |
| |
service.java.vm
| # |
| $!{define.vm} |
| |
| # |
| #setTableSuffix("Service") |
| |
| # |
| #save("/service", "Service.java") |
| |
| # |
| #setPackageSuffix("service") |
| |
| import com.baomidou.mybatisplus.extension.service.IService; |
| |
| # |
| #tableComment("表服务接口") |
| public interface $!{tableName} extends IService<$!tableInfo.name> { |
| |
| } |
| |
serviceImpl.java.vm
| |
| $!{define.vm} |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper; |
| import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; |
| import org.springframework.stereotype.Service; |
| |
| |
| |
| @Service |
| public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service { |
| |
| @Autowired |
| private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper; |
| |
| |
| } |
| |
mapper.java
| # |
| $!{define.vm} |
| |
| # |
| #setTableSuffix("Mapper") |
| |
| # |
| #save("/mapper", "Mapper.java") |
| |
| # |
| #setPackageSuffix("mapper") |
| |
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| import org.apache.ibatis.annotations.Mapper; |
| |
| # |
| #tableComment("表数据库访问层") |
| @Mapper |
| public interface $!{tableName} extends BaseMapper<$!tableInfo.name> { |
| |
| } |
| |
entity.java.vm
| ##引入宏定义 |
| $!define |
| |
| ##使用宏定义设置回调(保存位置与文件后缀) |
| #save(, ) |
| |
| ##使用宏定义设置包后缀 |
| #setPackageSuffix() |
| |
| ##使用全局变量实现默认包导入 |
| $!autoImport |
| import java.io.Serializable; |
| |
| ##使用宏定义实现类注释信息 |
| #tableComment() |
| public class $!{tableInfo.name} implements Serializable { |
| private static final long serialVersionUID = $!tool.serial(); |
| #foreach($column in $tableInfo.fullColumn) |
| #if(${column.comment})/** |
| * ${column.comment} |
| */#end |
| |
| private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; |
| #end |
| |
| #foreach($column in $tableInfo.fullColumn) |
| #getSetMethod($column) |
| #end |
| |
| @Override |
| public String toString(){ |
| return + |
| #foreach($column in $tableInfo.fullColumn) |
| + $column.name + + |
| #end |
| '}'; |
| } |
| } |
| |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)