求大神告诉我这段代码里的等号后边第一个where 是什么意思?第二个where是什么意思?还有sx为什么后边还要写个+
public List<GongWenLeiBie> getList(int sx)
{
String where="";
if(sx!=0)
{
where=where+"where shunXu="+sx+"";
}
return this.findAll(where);
}
第3行 是声明了一个变量where,其实是让你混淆,假设这个变量声明为N,或者其他的,是不是好读一些。
第6行 原文为 where=where+"where shunXu="+sx+""; 也就是N = N + “where shunXu ”的意思
转换理解 其实就是 where = where 原始值 + 这个变量值,假设where声明时是数值
声明 where = 1
那么 where = where(原始值为1) + 1
结果 where = 2
因为你的题目是字符串,所以
假设 where = "table " (其实应该是一句SQL语句,题目中是空值)
题目 where = where+"where shunXu="+sx+""
转换 where = "table (原始值)" + "where shunXu="+sx+""
结果 where = "table where shunXu=“+变量+""
其实这个方法意思是说获取一个泛型为的集合,判断参数变量sx,如果sx不为0则拼接字符串,最终按照findAll方法
返回泛型为集合
希望能帮到你
第一个where是变量名 第二个是字符串的内容
一个字符串罢了。和 String s = s +1,差不多
等号后面第一个where可以去掉,第二个where不能去掉,因为它是字符串
第二个 where在“”里面的,是一个字符串,就像“你好!”中的 你好 一样。