�磋��缁����村�ㄩ�㈢����绋�璇疯���浣���河渠茶��褰��剁��瑙�棰���绋�锛��板��锛�

https://edu.surowce-wtorne.com/sd/9cb7fLKADocument瑙�棰���绋�

涓���浠�缁�

�ㄥ����绔���绂伙���宸ユ�村����缁�����浠�澶╋�涓轰���广大���绔������板���河渠哄����娌�������锛��藉�璁╀�浠����板苟琛�寮���锛����朵��戒�璇���绔�����绔�寮���河渠哄�������扮演���ュ�f��妗g��涓��存�э��虫�舵�э�浠ユ�ゆ�ュぇ澶ф��楂�宸ヤ���������浠ュ�雾�颁�涓�河渠���甯镐�绉����ュ�g�$��宸ュ�凤��锋��浠h〃�х����Swagger锛���涓哄���藉���杩�娉ㄨВ��yml��JSON��杩版��浠舵�ヨ���ㄧ�����ュ�f��妗c��浣�����瑙�寰�疏浚�涓�绠℃���ㄩ��缃�杩�绋�杩���姝e父浣跨�ㄨ�绋��戒����瑰��濂界��锛��瑰����瀵瑰�硅薄���板��澶��������版敞��寰�涓���濂斤�瀵瑰��绔�寮���河渠哄���翠���濂姐��
��浠ワ�LKADocument璇���河渠�锛�LKADocument疏浚�涔���涓�娆惧�轰�Spring Web�藉��ㄨ���ㄧ�����ュ�f��妗g�$����JAVA���版��讹�娌¢��锛�纭�疏浚���swagger寰���锛�浣�姣�swagger�村��寮哄ぇ���鸿�斤��讳��ヨ�达�瑕�姣�swagger��缃��寸����锛�浣跨�ㄨ捣�ユ�存�逛究锛��ㄥ���版敞����UI灞�绀鸿�涓������芥�村��寮哄ぇ锛�浠讳�澶�����璇锋����板����搴����伴�借�藉��ㄦ拓宽瑙f��杩板�烘�ワ����蜂������ュ�e�ㄧ嚎璋�璇�锛�����rest椋��肩���ュ�c��UI��浣����㈡�寸����涓��界�搴������e�规划����跺�瑰��绔�����绔�寮���河渠哄���村����濂斤��瑰������绔�寮���河渠哄�������ュ��寮��剧��澶у�舵����涓�涓�寮哄ぇ�����斤�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

河渠���娣诲��LKADocument��浠跺��SpringBoot椤圭��

1.�ㄩ」���硅矾寰���寤轰�涓�lib��浠跺す锛���LKADocument瀵瑰���jar澶��惰���(����杩�娌℃���惧��maven涓�澶�������浠�搴�锛������ㄦ���板��ョ���瑰�)锛�
���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

2.��pom.xml娣诲��岛�璧�寮���:

<dependency>
    <groupId>LKADocument</groupId>
    <artifactId>LKADocument</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/LKADocument-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>

3.��application.yml娣诲����缃�:

lkad:
  basePackages: com.xb #��疏浚���������璺�寰�锛�澶�涓���璺�寰���浠�","��寮�
  projectName: lkad娴�璇�椤圭�� #椤圭����绉�
  description: �轰�LKADocument宸ュ�疯���ㄧ�������ュ�f��妗� #椤圭����杩�
  enabled: true #����寮���lkad���ㄧ�����ュ�f��妗�,榛�璁や负true

4.椤圭�����ㄧ把��涓�@LKADocument娉ㄨВ

package com.xb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.lk.api.annotation.LKADocument;
@SpringBootApplication
@LKADocument
public class LkaDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(LkaDemoApplication.class, args);
    }
}

5.��寮�缃��� http://127.0.0.1:8088/lkadocb.html锛�濡�����缃�娌℃����棰���浠ョ��涓�濡�涓�����锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

娉ㄦ��锛������ㄧ������Chrome娴�瑙��ㄨ�芥�e父��寮�锛�IE娴�瑙��ㄦ��寮��剧ず����棰�

涓���蹇����ラ��锛�

1.@LKAType娉ㄨВ锛�

璇存��锛�璇ユ拓宽瑙e�ㄧ把涓���浣跨��锛�涓轰��煎��Swagger涔���浠ョ��@Api娉ㄨВ�夸唬

浣���锛��ㄦ�ユ��璇���瑕�LKADocument������绫伙�璇ョ把��甯稿������瑕����ㄧ�����ュ�f��妗g��API锛�岛�濡�锛�甯哥�ㄧ��Controller绫�

灞��э�

value:绫昏�存��锛�濡�����@Api娉ㄨВ锛�姝ゅ��у��涓�tags锛�
description:绫绘��杩�(涓���蹇�椤�)

妗�岛�锛�

/**
绠���锛�@LKAType("娴�璇�绫�")
疏浚��寸��锛�@LKAType(value="娴�璇�绫�",description="璇ョ把�ㄦ�ユ�璇�LKADocument")
*/
@LKAType(value="娴�璇�绫�",description="璇ョ把�ㄦ�ユ�璇�LKADocument")
@RestController
public class TestController {....}

2.@LKAMethod娉ㄨВ锛�

璇存��锛�璇ユ拓宽瑙e�ㄦ�规�涓���浣跨��锛�����璇ユ�规���灞�绫诲��河渠�@LKAType娉ㄨВ��浼�����锛�涓轰��煎��Swagger涔���浠ョ��@ApiOperation娉ㄨВ�夸唬

浣���锛��ㄦ�ユ��璇���瑕�LKADocument�������规�锛�琚������扮演���规�浼����ㄧ�����ュ�f��妗�

灞��э�

value:�规�璇存��
description:�规���杩股�濡�����@ApiOperation娉ㄨВ锛�姝ゅ��у��涓�notes锛�
version:�����凤�榛�璁ゅ�间负"none"
contentType:contentType绫诲��,榛�璁ゅ�间负"application/x-www-form-urlencoded",杩������间负"application/json"

妗�岛�锛�

/**
绠���锛�@LKAMethod("hello娴�璇�")
疏浚��寸��锛�@LKAMethod(value="hello娴�璇�",description="娴�璇�@LKAMethod�规�",version="v1.0",contentType=Lkad.X_WWW_FORM_RULENCODED)
*/
@LKAMethod(value="hello娴�璇�",description="娴�璇��ュ��",version="v1.0",contentType="application/x-www-form-urlencoded")
@GetMapping("hello")
public String hello() {
    return "hello LKADocument";
}

�����撅�

����:

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

妯���:

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

3.@LKAParam娉ㄨВ��@LKAParams锛�

璇存��锛�璇ユ拓宽瑙e�ㄦ�规�涓���浣跨��锛�����璇ユ�规���河渠�@LKAMethod娉ㄨВ��浼�����锛�涓轰��煎��Swagger涔���浠ョ��@ApiImplicitParam��@ApiImplicitParams娉ㄨВ�夸唬

浣���锛��ㄦ�ユ��杩版�ュ�g���ュ��海洋�娈�

灞��э�

value:海洋�娈佃�存��
name:海洋�娈靛��绉�
description:海洋�娈垫��杩�
dataType:海洋�娈电被��,榛�璁ゅ�间负String
required:����蹇�椤股�����true��false,榛�璁ゅ�间负true
paramType:�ュ���瑰�锛�����query(params�ュ��),header(璇锋�澶村�ュ��),path(璇锋��板���ュ��),榛�璁ゅ�间负query
testData:娴�璇��版��
isArray:�������扮演��ュ��锛�����true��false锛�榛�璁や负false
type:瀵硅薄�ュ��锛����煎�硅薄绫诲��锛�濡����ュ����瀵硅薄锛�涓��㈤�や�name灞��у�濉��跺��灞��ч�芥����
group:瀵硅薄灞��у��缁�锛�����type灞��т娇��锛����煎��缁���绉帮�褰��ュ��涓���瑕�浼�瀵硅薄����灞��ф�跺���ㄦ�ゅ��у��缁�

妗�岛�1锛�

//params�ュ��
@LKAMethod(value="�规��ID�山���ㄦ�蜂俊��",version="v1.0")
//绠���:@LKAParam(value="�ㄦ��id",name="id")
@LKAParam(value="�ㄦ��id",name="id",description="�ㄦ��id",dataType="int",required=true,paramType=Lkad.QUERY,testData="1")
@GetMapping("getUser")
public User getUser(Integer id) {
    User user = new User();
    user.setId(id);
    user.setName("广大���");
    user.setEmail("123@qq.com");
    user.setAge(22);
    return user;
}
//����path�ュ��
@LKAMethod(value="�规��ID�山���ㄦ�蜂俊��",version="v1.0")
    //绠���:@LKAParam(value="�ㄦ��id",name="id")
    @LKAParam(value="�ㄦ��id",name="id",description="�ㄦ��id",dataType="int",required=true,paramType=Lkad.PATH,testData="1")
    @GetMapping("getUser/{id}")
    public User getUser2(@PathVariable("id")Integer id) {
        User user = new User();
        user.setId(id);
        user.setName("广大���");
        user.setEmail("123@qq.com");
        user.setAge(22);
        return user;
    }

������(��灞�绀烘����)锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

妗�岛�2锛�

@LKAMethod(value="�板��ㄦ�蜂俊��",version="v1.0")
@LKAParams({
    @LKAParam(value="�诲�token",name="x_token",description="�ㄦ�风�诲����������″�ㄨ�����浠ょ��",paramType=Lkad.HEADER,testData="lekwnddfekwes"),
    @LKAParam(value="�ㄦ�山��绉�",name="name",description="��澶�5涓�姹�海洋�",paramType=Lkad.QUERY,testData="广大���"),
    @LKAParam(value="�ㄦ�烽��绠�",name="email",required=false,paramType=Lkad.QUERY,testData="321@qq.com"),
    @LKAParam(value="�ㄦ�山勾榫�",name="age",description="18-30涔���",dataType="int",paramType=Lkad.QUERY,testData="20")
})
@GetMapping("addUser")
public Map<String,Object> addUser(String name,String email,Integer age,@RequestHeader("x_token")String x_token) {
    User user = new User();
    user.setId(2);
    user.setName(name);
    user.setEmail(email);
    user.setAge(age);

    Map<String,Object> map = new HashMap<>();
    map.put("code", 200);
    map.put("msg", "淇�海洋�����");
    map.put("result", x_token);
    return map;
}

������(��灞�绀烘����)锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

4.@LKAModel娉ㄨВ

璇存��锛�璇ユ拓宽瑙e�ㄥ�硅薄涓���浣跨��锛�涓轰��煎��Swagger涔���浠ョ��@ApiMode娉ㄨВ�夸唬

浣���锛��ㄦ�ユ��杩�model瀵硅薄

灞��э�

value:瀵硅薄璇存��
description:瀵硅薄��杩�

5.@LKAProperty娉ㄨВ

璇存��锛�璇ユ拓宽瑙e�ㄥ�硅薄灞��т���浣跨��锛�涓轰��煎��Swagger涔���浠ョ��@ApiModelProperty娉ㄨВ�夸唬

浣���锛��ㄦ�ユ��杩�model瀵硅薄��灞���

灞��э�

value:灞��ц�存��
description:灞��ф��杩�
dataType:海洋�娈电被��,榛�璁ゅ�间负String
required:����蹇�椤股�����true��false,榛�璁ゅ�间负true
paramType:�ュ���瑰�锛�����query(params�ュ��),header(璇锋�澶村�ュ��),path(璇锋��板���ュ��),榛�璁ゅ�间负query
testData:娴�璇��版��
isArray:�������扮演��ュ��锛�����true��false锛�榛�璁や负false
type:稳定�濂�瀵硅薄�ュ��锛����煎�硅薄绫诲��锛�濡����ュ����瀵硅薄锛�涓��㈤�や�name灞��у�濉��跺��灞��ч�芥����
groups:瀵硅薄灞��у��缁�锛�澶�涓���缁���","��寮�

妗�岛�锛�

/*User瀵硅薄*/
package com.xb.domain;

import com.lk.api.annotation.LKAModel;
import com.lk.api.annotation.LKAProperty;

@LKAModel("�ㄦ�山�硅薄")
public class User {
    @LKAProperty(value="�ㄦ��id",testData="3")
    private Integer id;
    @LKAProperty(value="�ㄦ�山��绉�",groups= {"add"},testData="广大�绾�")
    private String name;
    @LKAProperty(value="�ㄦ�烽��绠�",groups= {"add"},testData="456@qq.com")
    private String email;
    //groups灞���add���㈠��-n浠h〃姝ゅ���颁���蹇�椤荤��锛�涓���-n�芥��蹇�椤荤��
    @LKAProperty(value="�ㄦ�山勾榫�",groups= {"add-n"},testData="28")
    private Integer age;

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
}

/*娴�璇��ュ��*/
@LKAMethod(value="�板��ㄦ�蜂俊��2",version="v1.0")
@LKAParam(type=User.class,group="add")
@PostMapping("addUser2")
public Map<String,Object> addUser2(User user,@RequestHeader("x_token")String x_token) {

    Map<String,Object> map = new HashMap<>();
    map.put("code", 200);
    map.put("msg", "淇�海洋�����");
    Map<String,Object> map2 = new HashMap<>();
    map2.put("user", user);
    map2.put("x_token", x_token);
    map.put("result",map2);
    return map;
}

������(妯����山�)锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

6.@LKAGroup娉ㄨВ锛�

璇存��锛�璇ユ拓宽瑙e�ㄦ�规��ュ��瀵硅薄涓���浣跨��

浣���锛��ㄦ�ユ��疏浚��ュ��瀵硅薄灞��у��缁�锛�LKADocument ��浠ヨ���ㄦ����甯�@LKAModel娉ㄨВ��瀵硅薄锛���浠ュ�ㄦ�规�涓�����@LKAParam娉ㄨВ�ユ��杩板�ュ��瀵硅薄锛�杩��跺���瑕���疏浚���缁�广大卞��浠ョ��@Group娉ㄨВ

妗�岛�锛�

@LKAMethod(value="�板��ㄦ�蜂俊��3",version="v1.0")
@PostMapping("addUser3")
public Map<String,Object> addUser3(@LKAGroup("add")User user,@RequestHeader("x_token")String x_token) {

    Map<String,Object> map = new HashMap<>();
    map.put("code", 200);
    map.put("msg", "淇�海洋�����");
    Map<String,Object> map2 = new HashMap<>();
    map2.put("user", user);
    map2.put("x_token", x_token);
    map.put("result",map2);
    return map;
}

�����撅���浠���浠ョ���起���涓�涓�涓�妗�岛�������涓��风�� (妯����山�)锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

妗�岛�2锛�澶�����瀵硅薄�ュ��:

/*�板��瀵硅薄*/
package com.xb.domain;

import com.lk.api.annotation.LKAModel;
import com.lk.api.annotation.LKAProperty;

@LKAModel("�ㄦ�山�板��瀵硅薄")
public class Address {

    @LKAProperty("�板��ID")
    private Integer id;
    @LKAProperty(value="��浠�",groups= {"add2"},testData="婀���")
    private String province;
    @LKAProperty(value="��甯�",groups= {"add2"},testData="琛¢��")
    private String city;

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
}

/*瑙��插�硅薄*/
package com.xb.domain;

import com.lk.api.annotation.LKAModel;
import com.lk.api.annotation.LKAProperty;

@LKAModel("瑙��插�硅薄")
public class Role {
    @LKAProperty(value = "瑙���ID")
    private Integer id;
    @LKAProperty(value = "瑙��插��绉�",groups={"add2"},testData="绠$����")
    private String name;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

/*user瀵硅薄*/
package com.xb.domain;

import java.util.ArrayList;
import java.util.List;

import com.lk.api.annotation.LKAModel;
import com.lk.api.annotation.LKAProperty;

@LKAModel("�ㄦ�山�硅薄")
public class User {
    @LKAProperty(value="�ㄦ��id",testData="3")
    private Integer id;

    @LKAProperty(value="�ㄦ�山��绉�",groups= {"add","add2"},testData="广大�绾�")
    private String name;

    @LKAProperty(value="�ㄦ�烽��绠�",groups= {"add","add2"},testData="456@qq.com")
    private String email;

    @LKAProperty(value="�ㄦ�山勾榫�",groups= {"add-n","add2-n"},testData="28")
    private Integer age;

    @LKAProperty(type=Address.class,groups= {"add2"})
    private Address address;

    @LKAProperty(type=Role.class,isArray=true,groups= {"add2"})
    private List<Role> roles = new ArrayList<>();

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public Address getAddress() {
        return address;
    }
    public void setAddress(Address address) {
        this.address = address;
    }
    public List<Role> getRoles() {
        return roles;
    }
    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }
}

/*娴�璇��ュ��*/
@LKAMethod(value="�板��ㄦ�蜂俊��4",version="v1.0",contentType=Lkad.JSON)
    @PostMapping("addUser4")
    public Map<String,Object> addUser4(@RequestBody @LKAGroup("add2")User user,@RequestHeader("x_token")String x_token) {

        Map<String,Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "淇�海洋�����");
        Map<String,Object> map2 = new HashMap<>();
        map2.put("user", user);
        map2.put("x_token", x_token);
        map.put("result",map2);
        return map;
    }

�����撅�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

���������ュ�f��妗f�朵唬锛�姣�Swagger���芥�村己澶х��LKADocument�ュ�f��妗g�$��妗��惰����河渠�锛�

7.@LKAResposes��@LKARespose

璇存��锛�璇ユ拓宽瑙e�ㄦ�规�涓���浣跨��锛�����璇ユ�规���灞�绫诲��河渠�@LKAMethod娉ㄨВ��浼�����

浣���锛��ㄦ�ユ��杩版�ュ�g����搴�海洋�娈�

灞��э�

value:海洋�娈佃�存��
name:���板��绉�
description:���版��杩�
dataType:���扮演被�� default "String"
isArray:�������扮演��ュ��锛�����true��false锛�榛�璁や负false
parentName:�剁骇瀛�娈靛��绉�
type:�哄��model瀵硅薄绫诲��
group:�哄��model灞��у��缁�

妗�岛�锛���

����LKADocument��楂�绾у���

1.�扮演�璇锋��ュ������

2.澶�����璇锋�����搴�海洋�娈靛���芥�绀�

3.��浠朵�浼�����

4.淇��规�ュ�e���板�娉ㄤ俊��娣诲�������ゅ����

5.�跺������

�磋��缁����村�ㄩ�㈢����绋�璇疯���浣���河渠茶��褰��剁��瑙�棰���绋�锛��板��锛�

https://edu.surowce-wtorne.com/sd/9cb7fLKADocument瑙�棰���绋�