路径发布规范说明
1、e10接⼝路由分为三种
/api:⽤⼾需要登录e10才能访问,可以通过e10访问地址访问
/papi:不需要登录e10就能访问,可以通过e10访问地址访问
/sapi:e10服务间通信接⼝路由前缀,不能通过e10访问地址访问
2、接⼝代码统⼀部署在【weaver-secondev-service】二开服务中
3、总部二次开发规范,需要添加多一层【secondev】路径(这个规范是必须的)
4、泛微华南的开发则需要添加多一层【/broadsync】(这个规范是必须的)
例如:
/api/secondev/broadsync/xxx/xxx
/papi/secondev/broadsync/xxx/xxx
/sapi/secondev/broadsync/xxx/xxx
类上使用注解(虽然可以多个,但是不建议同时出现,三选一 api/papi/sapi):
@RestController
@RequestMapping({"/api/secondev/broadsync/demo", "/papi/secondev/broadsync/demo", "/sapi/secondev/broadsync/demo"})
方法上注解:
@GetMapping("/getTest") get请求方式
@PostMapping("/postTest") post方式
package路径:
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
基本代码结构
注解是RestController
@RestController
注解定义api路由,可以多个
@RequestMapping({"/papi/secondev/broadsync/demo"})
public class ApiDemo {
//GET请求
@GetMapping("/getTest") @RequestParam参数为头参数
public WeaResult<String> getTest(@RequestParam Map<String,Object> params){
String result = JSON.toJSONString(params);
log.info("/getTest==inParams==>" + result);
return WeaResult.success("收到参数==>" + result);
}
//POST请求 参数为@RequestBody对象
@PostMapping("/postTest")
public WeaResult<String> PostTest(@RequestBody Map<String,Object> params){
String result = JSON.toJSONString(params);
return WeaResult.success("收到参数==>" + result);
}
}
如果获取当前用户或者租户信息
package路径:
import com.weaver.teams.security.context.UserContext;
import com.weaver.teams.security.user.User;
注意papi用户可能为空,因为改接口是不需要登录就可以调用
final User currentUser = UserContext.getCurrentUser();
//final Tenant currentTenant = TenantContext.getCurrentTenant();
final Long employeeId = currentUser.getEmployeeId();//用户
final String tenantKey = currentUser.getTenantKey();//租户
package com.weaver.seconddev.broadsync;
import com.alibaba.fastjson.JSON;
import com.weaver.emonitor.bean.WeaResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@Slf4j
//注解是RestController
@RestController
//注解定义api路由,可以多个
@RequestMapping({"/api/secondev/broadsync/demo"})
public class ApiDemo {
//GET请求
@GetMapping("/getTest")
public WeaResult<String> getTest(@RequestParam Map<String,Object> params){
final User currentUser = UserContext.getCurrentUser();
//final Tenant currentTenant = TenantContext.getCurrentTenant();
final Long employeeId = currentUser.getEmployeeId();//用户
final String tenantKey = currentUser.getTenantKey();//租户
String result = JSON.toJSONString(params);
log.info("/getTest==inParams==>" + result);
return WeaResult.success("收到参数==>" + result);
}
//POST请求
@PostMapping("/postTest")
public WeaResult<String> PostTest(@RequestBody Map<String,Object> params){
final User currentUser = UserContext.getCurrentUser();
//final Tenant currentTenant = TenantContext.getCurrentTenant();
final Long employeeId = currentUser.getEmployeeId();//用户
final String tenantKey = currentUser.getTenantKey();//租户
String result = JSON.toJSONString(params);
return WeaResult.success("收到参数==>" + result);
}
}