# 数据XML出参
后端返回数据之前,可以通过配置XML,对返回数据进行处理,然后输出给前端。
每个案例输出格式
- 查询接口
- query.js
- 入参json
- 输出sql
- 返回结果
# 单表数据输出
方式一:通过类注解的方式,单表数据输出
访问接口
sys/user/list
XML配置
<grid name="LIST">
<col type="yui.bss.demo.vo.SysUserVo" />
</grid>
返回结果
{
"code": 0,
"header": {
"typeDsr": "类型(0:管理员,1:非管理员)描述",
"id": "ID",
"roleId": "角色ID",
"username": "登录名",
"email": "邮件",
"rmks": "备注",
"type": "类型(0:管理员,1:非管理员)"
},
"data": {
"list": [
{
"id": 1,
"roleId": 1,
"username": "admin",
"email": "demo@163.com",
"rmks": "admin",
"type": 0,
"typeDsr": "管理员"
},
{
"id": 2,
"roleId": 2,
"username": "anno",
"email": "anno@163.com",
"rmks": "anno",
"type": 2,
"typeDsr": "匿名用户"
},
{
"id": 3,
"roleId": 3,
"username": "test",
"email": "test@163.com",
"rmks": "test",
"type": 1,
"typeDsr": "普通用户"
}
]
}
}
方式二:通过逐行配置的方式,单表数据输出
访问接口
sys/user/list2
XML配置
<grid name="LIST2">
<col name="username" mapper="sysUserVo.username" descr="登陆名" />
<col name="email" mapper="sysUserVo.email" descr="邮件" />
</grid>
返回结果
{
"code": 0,
"header": {
"username": "登陆名",
"email": "邮件"
},
"data": {
"list": [
{
"username": "admin",
"email": "demo@163.com"
},
{
"username": "anno",
"email": "anno@163.com"
},
{
"username": "test",
"email": "test@163.com"
}
]
}
}
# 一对一连查输出
多表连查(内连接,左连接,右连接),输出数据
方式一:通过类注解的方式输出
访问接口
sys/user/listUserARole
XML配置
<grid name="USER_ROLE">
<col type="yui.bss.demo.vo.SysUserVo" />
<col prefix="role" type="yui.bss.demo.vo.SysRoleVo" />
</grid>
返回结果
{
"code": 0,
"header": {
"typeDsr": "类型(0:管理员,1:非管理员)描述",
"id": "ID",
"roleId": "ID",
"username": "登录名",
"email": "邮件",
"rmks": "备注",
"type": "类型(0:管理员,1:非管理员)",
"roleCd": "编码",
"roleNm": "名称",
"roleRmks": "备注"
},
"data": {
"list": [
{
"id": 1,
"roleId": 1,
"username": "admin",
"email": "demo@163.com",
"rmks": "admin",
"type": 0,
"roleCd": "ROLE_ADMIN",
"roleNm": "管理员",
"roleRmks": "管理员",
"typeDsr": "管理员"
},
{
"id": 2,
"roleId": 2,
"username": "anno",
"email": "anno@163.com",
"rmks": "anno",
"type": 2,
"roleCd": "ROLE_ANON",
"roleNm": "匿名",
"roleRmks": "匿名",
"typeDsr": "匿名用户"
},
{
"id": 3,
"roleId": 3,
"username": "test",
"email": "test@163.com",
"rmks": "test",
"type": 1,
"roleCd": "ROLE_TEST",
"roleNm": "测试角色",
"roleRmks": "测试",
"typeDsr": "普通用户"
}
]
}
}
方式二:通过逐行配置的方式输出
访问接口
sys/user/listUserARole2
XML配置
<grid name="USER_ROLE2">
<col name="username" mapper="sysUserVo.username" descr="登陆名" />
<col name="email" mapper="sysUserVo.email" descr="邮件" />
<col name="roleCd" mapper="sysRoleVo.cd" descr="编码" />
<col name="roleNm" mapper="sysRoleVo.nm" descr="名称" />
</grid>
返回结果
{
"code": 0,
"header": {
"username": "登陆名",
"email": "邮件",
"roleCd": "编码",
"roleNm": "名称"
},
"data": {
"list": [
{
"username": "admin",
"email": "demo@163.com",
"roleCd": "ROLE_ADMIN",
"roleNm": "管理员"
},
{
"username": "anno",
"email": "anno@163.com",
"roleCd": "ROLE_ANON",
"roleNm": "匿名"
},
{
"username": "test",
"email": "test@163.com",
"roleCd": "ROLE_TEST",
"roleNm": "测试角色"
}
]
}
}
每个案例输出格式
prefix="role"
表示对注解类的属性前面加上前缀
# 一对多查询输出
一对多数据查询输出,可以即可一对多,且多中又可以有一对一查询
方式一:通过类注解的方式输出
访问接口
sys/user/listUserWRole
XML配置
<grid name="USER_W_ROLE">
<col type="yui.bss.demo.vo.SysUserVo" />
<collection name="roleList" mapper="sysRoleDtoList">
<col type="yui.bss.demo.vo.SysRoleVo" />
</collection>
</grid>
返回结果
{
"code": 0,
"header": {
"typeDsr": "类型(0:管理员,1:非管理员)描述",
"roleList": {
"id": "ID",
"cd": "编码",
"nm": "名称",
"rmks": "备注"
},
"id": "ID",
"roleId": "角色ID",
"username": "登录名",
"email": "邮件",
"rmks": "备注",
"type": "类型(0:管理员,1:非管理员)"
},
"data": {
"list": [
{
"roleList": [
{
"id": 1,
"cd": "ROLE_ADMIN",
"nm": "管理员",
"rmks": "管理员"
}
],
"id": 1,
"roleId": 1,
"username": "admin",
"email": "demo@163.com",
"rmks": "admin",
"type": 0,
"typeDsr": "管理员"
},
{
"roleList": [
{
"id": 2,
"cd": "ROLE_ANON",
"nm": "匿名",
"rmks": "匿名"
}
],
"id": 2,
"roleId": 2,
"username": "anno",
"email": "anno@163.com",
"rmks": "anno",
"type": 2,
"typeDsr": "匿名用户"
},
{
"roleList": [
{
"id": 3,
"cd": "ROLE_TEST",
"nm": "测试角色",
"rmks": "测试"
}
],
"id": 3,
"roleId": 3,
"username": "test",
"email": "test@163.com",
"rmks": "test",
"type": 1,
"typeDsr": "普通用户"
}
]
}
}
方式二:通过逐行配置的方式输出
访问接口
sys/user/listUserWRole2
XML配置
<grid name="USER_W_ROLE2">
<col name="username" mapper="sysUserVo.username" descr="登陆名" />
<col name="email" mapper="sysUserVo.email" descr="邮件" />
<collection name="roleList" mapper="sysRoleDtoList">
<col name="roleCd" mapper="sysRoleVo.cd" descr="编码" />
<col name="roleNm" mapper="sysRoleVo.nm" descr="名称" />
</collection>
</grid>
返回结果
{
"code": 0,
"header": {
"username": "登陆名",
"email": "邮件",
"roleList": {
"roleCd": "编码",
"roleNm": "名称"
}
},
"data": {
"list": [
{
"username": "admin",
"email": "demo@163.com",
"roleList": [
{
"roleCd": "ROLE_ADMIN",
"roleNm": "管理员"
}
]
},
{
"username": "anno",
"email": "anno@163.com",
"roleList": [
{
"roleCd": "ROLE_ANON",
"roleNm": "匿名"
}
]
},
{
"username": "test",
"email": "test@163.com",
"roleList": [
{
"roleCd": "ROLE_TEST",
"roleNm": "测试角色"
}
]
}
]
}
}
每个案例输出格式
header
,根据自己的要求,可以在生产环境去除
赞助商