赞
踩
一. Swagger2 配置
springboot 目录下新建 config 文件夹
-
- @Bean
- public Docket createRestApi() {
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- //是否开启 (true 开启 false隐藏。生产环境建议隐藏)
- //.enable(false)
- .select()
- //扫描的路径包,设置basePackage会将包下的所有被@Api标记类的所有方法作为api
- .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
- //指定路径处理PathSelectors.any()代表所有的路径
- .paths(PathSelectors.any())
- .build();
- }
-
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- //设置文档标题(API名称)
- .title("SpringBoot中使用Swagger2接口规范")
- //文档描述
- .description("接口说明")
- //服务条款URL
- .termsOfServiceUrl("http://localhost:8080/")
- //版本号
- .version("1.0.0")
- .build();

二.Swagger2进入方法
http://localhost:8080/swagger-ui.html(8080为自己端口号)
三.简单运用
在springboot项目的xml文件中插入post配置
示例如下
- <insert id="add" parameterType="com.example.demo.test.intellect" >
- insert into intellectualproperty(companyid, `time`, kind, `name`, material, updatetime) value(#{companyid},#{time},#{kind},#{name},#{material},#{updatetime})
- </insert>
其中 intellectualproperty 为数据库表名()中为对象浏览器中各参数名
在mapper中添加
boolean add(intellect intellect);
service中对应添加
boolean add(intellect intellect);
最后在controller中添加
- @PostMapping("/add")
- public boolean add(@RequestBody intellect intellect){
- return intellservice.add(intellect);
然后运行成功后进入
http://localhost:8080/swagger-ui.html(8080为端口号)
点击intell(对应项目)
点击add Post
点击Try it out
即可实现增删改查中的增(POST)
ps:应删除“id”:0,因为功能实现后会自动生成id
运行成功示例
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。