标签:返回 comm class 简单的 ber tco inf seq 动态
经过后端的辛勤努力,我们终于实现了以上图的内容
因为安卓队还不能将读取到的JSON对象写到安卓界面
测试主要是后端的同学来测试,由其他同学提出测试样例
主要用我们写的软件,发送JSON对象给JDBC进行操作
但是在进行连接前要进行用户验证
如果验证失败无法进行登录
接下来将用简单的套接口软件进行测试展示
登陆成功返回用户ID,学号,头像等信息,才可以进行下一步操作
接下来的操作,将采用JSON格式进行发送命令
为此,我们制定了JDBC的语言风格
requests是安卓发给JDBC的数据,commands是JDBC转给数据库的语言
requests[0]="@getMasterpage";
commands[0]="select * from masterpage limit ?,?"; //两参数,建议0,10
requests[1]="@searchUserName";
commands[1]="select * from User where UserName like ? limit ?,?";//三参数,建议0,20
requests[2]="@searchUserID";
commands[2]="select * from User where UserID=?";//一参数
requests[3]="@searchPostContent";
commands[3]="select * from masterpage where PostContent like ? order by PostTime desc limit ?,?";//三参数,建议0,10
requests[4]="@searchTagName";
commands[4]="select distinct * from Tag where TagName like ? limit ?,?";//三参数,其中1为%内容%,2,3建议0,20
requests[5]="@searchTagID";
commands[5]="select distinct * from Tag where TagID =?";//一参 ID值
requests[6]="@searchTagSequenceID";
commands[6]="select * from Tag where TagSequenceID=?";//一参 ID值
requests[7]="@searchPersonalTag";
commands[7]="select * from PersonalTag where UserID = ? order by OrderNumber";//一参 ID值
requests[8]="@getPost";
commands[8]="select * from masterpage where PostID=?";//点击动态
requests[9]="@searchPostByTag";
commands[9]="SELECT DISTINCT u.UserName,u.UserPictureURL,u.UserID,\n" +
"t.TagTruth,p.PostID,p.PostTime,p.PostContent,p.PicturesURL,\n" +
"p.LikeNumber,p.CollectNumber,p.CommentNumber\n" +
"FROM Post AS p ,Tag AS t,User AS u\n" +
"WHERE u.UserID=p.UserID AND p.TagMark=t.TagID AND\n" +
"u.UserID IN (SELECT uu.UserID\n" +
"FROM Post AS pp ,Tag AS tt,User AS uu\n" +
"WHERE uu.UserID=pp.UserID AND pp.TagMark=tt.TagID AND uu.UserID<>?\n" +
"AND tt.TagID IN (SELECT TagID\n" +
"FROM PersonalTag\n" +
"WHERE PersonalTag.UserID=?\n" +
")\n" +
")";
封装样式
JSONObject jsonObject=new JSONObject();
jsonObject.put("request","@searchUserID");//命令名称
jsonObject.put("parameter",1);//参数个数
jsonObject.put(0,1);//第0个参数,学号为1
String sql=jsonObject.toString();//直接发送给服务器
0.0.3版本模糊查询需要在发送端加上通配符 “%”+content+“%”
其中以requests[0]为举例,安卓端发送
{"request":"@getMasterpage","parameter":2,"0":0,"1":10}
在JDBC里将转化为以下语言给数据库
select * from masterpage limit 0,10
masterpage是数据库的视图,这句话实际上等同于
select distinct u.UserName,u.UserPictureURL,u.UserID,t.TagTruth,p.PostID,p.PostTime,p.PostContent,p.PicturesURL,p.LikeNumber,p.CollectNumber,p.CommentNumber
from Post as p ,Tag as t,User as u where u.UserID=p.UserID and p.TagMark=t.TagID order by p.PostTime desc;
得到的结果如下
即获取了所有的动态内容
用到了requests[9]命令
为了更好展示我们举个例子
尚佳同学的用户ID是3
他对1010010000和1010020000的标签感兴趣
TagMark是显示在个人空间里的标签备注,所以不会显示在“同好动态”里
这是所有的动态,第一四条为1010010000标签相关动态,第二条是1010020000标签相关动态
即要查出三条结果
如果如果用SQL语句来写出这段话的话,即为
/*同好圈(返回拥有相同爱好标签的所有动态)*/
/*@UserID(用户ID变量)*/
SELECT DISTINCT u.UserName,u.UserPictureURL,u.UserID,
t.TagTruth,p.PostID,p.PostTime,p.PostContent,p.PicturesURL,
p.LikeNumber,p.CollectNumber,p.CommentNumber
FROM Post AS p ,Tag AS t,User AS u
WHERE u.UserID=p.UserID AND p.TagMark=t.TagID AND
u.UserID IN (SELECT uu.UserID
FROM Post AS pp ,Tag AS tt,User AS uu
WHERE uu.UserID=pp.UserID AND pp.TagMark=tt.TagID AND uu.UserID<>3
AND tt.TagID IN (SELECT TagID
FROM PersonalTag
WHERE PersonalTag.UserID=3
)
);
最后我们整合了一下,只需要一句话就可以表达上面的内容
{"request":"@searchPostByTag","parameter":1,"0":3}
返回的结果因为安卓还未做出界面来,所以先用IDEA展示
用request[1]来查找名字带“莫”的人
{"request":"@searchUserName","parameter":3,"0":'%莫%',"1":0,"2":10}
剩余的测试内容太多
因为我们的安卓端还无法读取JSON对象
所以我们用贴图带过
requests[2]="@searchUserID";
commands[2]="select * from User where UserID=?";//一参数
requests[3]="@searchPostContent";
commands[3]="select * from masterpage where PostContent like ? order by PostTime desc limit ?,?";//三参数,建议0,10
requests[4]="@searchTagName";
commands[4]="select distinct * from Tag where TagName like ? limit ?,?";//三参数,其中1为%内容%,2,3建议0,20
requests[5]="@searchTagID";
commands[5]="select distinct * from Tag where TagID =?";//一参 ID值
requests[6]="@searchTagSequenceID";
commands[6]="select * from Tag where TagSequenceID=?";//一参 ID值
requests[7]="@searchPersonalTag";
commands[7]="select * from PersonalTag where UserID = ? order by OrderNumber";//一参 ID值
requests[8]="@getPost";
commands[8]="select * from masterpage where PostID=?";//点击动态
标签:返回 comm class 简单的 ber tco inf seq 动态
原文地址:https://www.cnblogs.com/fzu-tonghao/p/11863260.html