freemaker模板

编程入门 行业动态 更新时间:2024-10-07 20:33:45

freemaker<a href=https://www.elefans.com/category/jswz/34/1770549.html style=模板"/>

freemaker模板


controller生成模板 

package ${package.Controller};import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import tech.niua.core.annotation.ApiVersion;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import tech.niua.core.enums.BusinessType;
import tech.niuamon.model.ResultCode;
import tech.niuamon.model.ResultJson;
import java.util.Arrays;
import tech.niuamon.utils.poi.ExcelUtil;
import java.util.List;
import org.apachemons.lang3.StringUtils;
import tech.niua.core.annotation.NoRepeatSubmit;
import tech.niua.core.annotation.Log;/*** <p>*  ${tablement} 控制类* </p>** @author niua* @since ${.now?string("yyyy-MM-dd HH:mm:ss")}*/
@RestController
@ApiVersion(1)
@RequestMapping("{version}/${entity ?uncap_first}")
public class ${table.controllerName} {@Autowiredprivate ${table.serviceName} ${entity?uncap_first}Service;/*** 查询列表** @param currentPage* @param pageSize* @param ${entity?uncap_first}* @return*/@Log(value = "查询列表", businessType = BusinessType.LIST)@PreAuthorize("hasAuthority('/${entity?uncap_first}')")@ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})@PostMapping("/list/{currentPage}/{pageSize}")public ResultJson index(@PathVariable Integer currentPage, @PathVariable Integer pageSize,@RequestBody  ${entity} ${entity?uncap_first}) {QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
<#list table.fields as field >
<#if (field.propertyName != "id" && field.propertyName != "createTime" && field.propertyName != "updateTime") ><#if field.propertyType == "String">if(StringUtils.isNotBlank(${entity?uncap_first}.get${field.propertyName?cap_first}())) {queryWrapper.like("${field.name}", ${entity?uncap_first}.get${field.propertyName?cap_first}());}</#if><#if field.propertyName == "deleteFlag">queryWrapper.eq("${field.name}", 0);</#if>
</#if><#if field.propertyName == "createTime">if(${entity?uncap_first}.get${field.propertyName?cap_first}Begin() != null && ${entity?uncap_first}.get${field.propertyName?cap_first}End()  != null ){queryWrapper.between("${field.name}", ${entity?uncap_first}.get${field.propertyName?cap_first}Begin(), ${entity?uncap_first}.get${field.propertyName?cap_first}End());}queryWrapper.orderByDesc("create_time");</#if>
</#list>IPage<${entity}> pageList = ${entity?uncap_first}Service.page(new Page<>(currentPage, pageSize), queryWrapper);return ResultJson.ok(pageList);}/***根据id查找* @param: id* @return*/@PreAuthorize("hasAuthority('/${entity?uncap_first}')")@ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})@GetMapping("/findById/{id}")public ResultJson find${entity}ById(@PathVariable Long id) {QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();queryWrapper.eq("id", id);<#list table.fields as field ><#if field.propertyName == "deleteFlag">queryWrapper.eq("${field.name}", 0);</#if></#list>${entity} ${entity ?uncap_first} = ${entity ?uncap_first}Service.getOne(queryWrapper);if(${entity ?uncap_first} != null){return ResultJson.ok(${entity ?uncap_first});}return ResultJson.failure(ResultCode.BAD_REQUEST);}/*** 添加修改* @param ${entity?uncap_first}* @return*/@Log(value = "添加修改", businessType = BusinessType.INSERTORUPDATE)@PreAuthorize("hasAuthority('/${entity?uncap_first}/saveOrUpdate')")@NoRepeatSubmit@ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})@PostMapping("/saveOrUpdate")public ResultJson saveOrUpdate(@RequestBody ${entity} ${entity?uncap_first}){boolean flag = ${entity?uncap_first}Service.saveOrUpdate(${entity?uncap_first});if(flag){return ResultJson.ok();}return ResultJson.failure(ResultCode.NOT_UPDATE);}/*** 删除* @param ids* @return*/@Log(value = "删除", businessType = BusinessType.DELETE)@PreAuthorize("hasAuthority('/${entity?uncap_first}/delete')")@ApiImplicitParams({@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header")})@GetMapping("/delete")public ResultJson delete(@RequestParam("ids") Long[] ids){
<#assign dt=0>
<#list table.fields as field><#if field.propertyName == "deleteFlag"><#assign dt=1></#if>
</#list><#if dt==1>UpdateWrapper<${entity}> updateWrapper = new UpdateWrapper<>();updateWrapper.in("id",ids).set("delete_flag",1);boolean updateFlag = ${entity?uncap_first}Service.update(null,updateWrapper);if(updateFlag){return ResultJson.ok(updateFlag);}return ResultJson.failure(ResultCode.SERVER_ERROR);<#else>boolean updateFlag = ${entity?uncap_first}Service.removeByIds(Arrays.asList(ids));if(updateFlag){return Re

更多推荐

freemaker模板

本文发布于:2024-03-23 15:26:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1739763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   freemaker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!