diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/controller.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/controller.tpl index b8d375a3..27d43b10 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/controller.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/controller.tpl @@ -1,11 +1,17 @@ #set(tableComment = table.getComment()) #set(entityClassName = table.buildEntityClassName()) +#set(entityVarName = firstCharToLowerCase(entityClassName)) #set(serviceVarName = firstCharToLowerCase(table.buildServiceClassName())) package #(packageConfig.controllerPackage); -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.PathVariable; +import com.mybatisflex.core.paginate.Page; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired; import #(packageConfig.entityPackage).#(entityClassName); import #(packageConfig.servicePackage).#(table.buildServiceClassName()); @@ -19,6 +25,7 @@ import #(controllerConfig.buildSuperClassImport()); #end import java.io.Serializable; +import java.util.List; /** * #(tableComment) 控制层。 @@ -36,9 +43,52 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.supperClas @Autowired private #(table.buildServiceClassName()) #(serviceVarName); - + /** - * 根据#(tableComment)获取详细信息。 + * 添加#(tableComment)。 + * + * @param #(entityVarName) #(tableComment) + * @return {@code true} 添加成功,{@code false} 添加失败 + */ + @PostMapping("save") + public boolean save(@RequestBody #(entityClassName) #(entityVarName)) { + return #(serviceVarName).save(#(entityVarName)); + } + + /** + * 根据主键删除#(tableComment)。 + * + * @param id 主键 + * @return {@code true} 删除成功,{@code false} 删除失败 + */ + @DeleteMapping("remove/{id}") + public boolean remove(@PathVariable Serializable id) { + return #(serviceVarName).removeById(id); + } + + /** + * 根据主键更新#(tableComment)。 + * + * @param #(entityVarName) #(tableComment) + * @return {@code true} 更新成功,{@code false} 更新失败 + */ + @PutMapping("update") + public boolean update(@RequestBody #(entityClassName) #(entityVarName)) { + return #(serviceVarName).updateById(#(entityVarName)); + } + + /** + * 查询所有#(tableComment)。 + * + * @return 所有数据 + */ + @GetMapping("list") + public List<#(entityClassName)> list() { + return #(serviceVarName).list(); + } + + /** + * 根据#(tableComment)主键获取详细信息。 * * @param id #(tableComment)主键 * @return #(tableComment)详情 @@ -48,4 +98,15 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.supperClas return #(serviceVarName).getById(id); } + /** + * 分页查询#(tableComment)。 + * + * @param page 分页对象 + * @return 分页对象 + */ + @GetMapping("page") + public Page<#(entityClassName)> page(Page<#(entityClassName)> page) { + return #(serviceVarName).page(page); + } + } \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/package-info.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/package-info.tpl index 2d8bc9e6..a86e5048 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/package-info.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/package-info.tpl @@ -1,6 +1,7 @@ /** - * #(javadocConfig.formatPackageComment(packageName)) + * #(packageComment) * + * @author #(javadocConfig.getAuthor()) * @since #(javadocConfig.getSince()) */ package #(packageName); \ No newline at end of file