大家都知道 查询一个 二个 三个分类 查询 都很简单 也无非就是几种情况
假如四种以上分类查询怎么办啊 请问高手们有没有什么好的优化方法
下面是我的 4个个分类查询的 代码 我感觉好长啊
String phone = request.getParameter("phone") == null ? "" : request
.getParameter("phone");
String content = request.getParameter("content") == null ? "" : request
.getParameter("content");
String front = request.getParameter("front") == null ? "" : request
.getParameter("front");
String back = request.getParameter("back") == null ? "" : request
.getParameter("back");
if (phone.equals("") && content.equals("") && front.equals("")
&& back.equals("")) {
str = "";
} else if ((!phone.equals("")) && (!content.equals(""))
&& (!front.equals("")) && (!back.equals(""))
&& (!front.equals(back))) {
str = "where senderAddress like '%" + phone
+ "%' and notifMessage like '%" + content
+ "%' and times >'" + front + "' and times<'" + back + "' ";
} else if (phone.equals("") && (!content.equals(""))
&& (!front.equals("")) && (!back.equals(""))
&& (!front.equals(back))) {
str = "where notifMessage like '%" + content + "%' and times >'"
+ front + "' and times<'" + back + "' ";
} else if (phone.equals("") && content.equals("")
&& (!front.equals("")) && (!back.equals(""))
&& (!front.equals(back))) {
str = "where times >'" + front + "' and times<'" + back + "' ";
} else if (phone.equals("") && content.equals("")
&& (!front.equals("")) && (!back.equals(""))
&& front.equals(back)) {
str = "where times >'" + front + " 00:00:00' and times<'" + back
+ " 23:59:59'";
} else if (phone.equals("") && content.equals("") && front.equals("")
&& (!back.equals(""))) {
str = "where times<'" + back + " 23:59:59'";
} else if ((!phone.equals("")) && content.equals("")
&& (!front.equals("")) && (!back.equals(""))
&& (!front.equals(back))) {
str = "where senderAddress like '%" + phone + "%' and times >'"
+ front + "' and times<'" + back + "' ";
} else if ((!phone.equals("")) && content.equals("")
&& (!front.equals("")) && (!back.equals(""))
&& front.equals(back)) {
str = "where times >'" + front + " 00:00:00' and times<'" + back
+ " 23:59:59' and senderAddress like '%" + phone + "%'";
} else if ((!phone.equals("")) && content.equals("")
&& front.equals("") && (!back.equals(""))) {
str = "where times<'" + back
+ " 23:59:59' and senderAddress like '%" + phone + "%'";
} else if ((!phone.equals("")) && (!content.equals(""))
&& front.equals("") && (!back.equals(""))) {
str = "where senderAddress like '%" + phone
+ "%' and notifMessage like '%" + content
+ "%' and times<'" + back + "' ";
} else if ((!phone.equals("")) && (!content.equals(""))
&& front.equals("") && back.equals("")) {
str = "where senderAddress like '%" + phone
+ "%' and notifMessage like '%" + content + "%'";
} else if ((!phone.equals("")) && (!content.equals(""))
&& (!front.equals("")) && back.equals("")) {
str = "where senderAddress like '%" + phone
+ "%' and notifMessage like '%" + content
+ "%' and times >'" + front + "' ";
} else if ((!phone.equals("")) && content.equals("")
&& front.equals("") && back.equals("")) {
str = "where senderAddress like '%" + phone + "%'";
} else if (phone.equals("") && (!content.equals(""))
&& front.equals("") && back.equals("")) {
str = "where notifMessage like '%" + content + "%'";
} else if (phone.equals("") && content.equals("")
&& (!front.equals("")) && back.equals("")) {
str = "where times >'" + front + " 00:00:00'";
} else if (phone.equals("") && (!content.equals(""))
&& (!front.equals("")) && back.equals("")) {
str = "where times >'" + front
+ " 00:00:00' and notifMessage like '%" + content + "%'";
} else if (phone.equals("") && (!content.equals(""))
&& front.equals("") && (!back.equals(""))) {
str = "where times<'" + back
+ " 23:59:59' and notifMessage like '%" + content + "%'";
} else if ((!phone.equals("")) && content.equals("")
&& (!front.equals("")) && back.equals("")) {
str = "where times >'" + front
+ " 00:00:00' and senderAddress like '%" + phone + "%'";
}