idea自定义模板,配置文件没提示

1、idea中自定义模板

为了避免敲重复相同类的代码,可以使用模板进行生成。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2xkRzufV-1585376698150)(assets/1585206058297.png)]

样板代码

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxm.entity.${NAME};
import com.zxm.service.${NAME}Service;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/PREFIX/${NAME}")
public class ${NAME}Controller {

    @Reference(check = false)
    private ${NAME}Service service;

    @GetMapping("/page")
    @RequiresPermissions("PREFIX:${NAME}:page")
    @ApiOperation("分页查询${NAME}")
    public ResponseEntity<IPage<${NAME}>> queryByPage(Page<${NAME}> page, ${NAME} condition) {
        IPage<${NAME}> pageDate = service.queryByPage(page, condition);
        return ResponseEntity.ok(pageDate);
    }


    @PostMapping
    @RequiresPermissions("PREFIX:${NAME}:save")
    @ApiOperation("新增一个${NAME}")
    public ResponseEntity<Void> save(@RequestBody @Valid ${NAME} entity) {
        service.save(entity);
        return ResponseEntity.ok().build();
    }

    @PutMapping
    @RequiresPermissions("PREFIX:${NAME}:update")
    @ApiOperation("根据id修改${NAME}")
    public ResponseEntity<Void> update(@RequestBody @Valid ${NAME} entity) {
        service.updateById(entity);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping("/{id}")
    @RequiresPermissions("PREFIX:${NAME}:delete")
    @ApiOperation("删除${NAME}")
    public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
        service.removeById(id);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/info/{id}")
    @RequiresPermissions("PREFIX:${NAME}:info")
    @ApiOperation("查询${NAME}详情")
    public ResponseEntity<${NAME}> info(@PathVariable("id") Long id) {
        ${NAME} entity = service.getById(id);
        return ResponseEntity.ok(entity);
    }
}

使用样板

新建类后,填写controller层的前缀。创建成功后,使用ctrl+r进行替换固定值。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3E2XUtkF-1585376698152)(assets/1585206208101.png)]

2、配置文件中没有提示

自定义的配置文件前缀没有提示。

原因:

该类没有编译成功。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9S3M02u2-1585376698156)(assets/1585208821281.png)]

解决:

依赖不可少:

<!--配置文件提示包-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

1、删除已编译的类(target文件夹)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5hSuTP9c-1585376698157)(assets/1585208998699.png)]

2、使用idea中的锤子进行编译

扫描二维码关注公众号,回复: 10381840 查看本文章

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-EhLi1l9d-1585376698159)(assets/1585209087898.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vr3s5KGI-1585376698160)(assets/1585209176708.png)]

发布了29 篇原创文章 · 获赞 0 · 访问量 2237

猜你喜欢

转载自blog.csdn.net/rootDream/article/details/105160757