---
title: "初始化后 条件怎么写！！"
author: "ljl.java"
date: "2013-02-04T22:04:28Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-02-04T22:04:28Z"
id: 1788831
url: "https://ljl-java.iteye.com/blog/1788831"
---

一个条件判断 因其条件不够严密 查询结果各种奇葩

前台freemarker 传来的参数

\[@cms\_infoCategory\_FlagDirective count='3' recommend\_flag='0'  show\_category=‘1’ ]

后台

定义变量（因需要组合拼接）Action层

String show\_category = "";

String show\_category\_s = "";

String show\_compose = "";

String Comma = ",";

String recommend\_flag = "";

if ((show\_category != null && !show\_category.equals(""))

&& (show\_category\_s != null) && !show\_category\_s.equals("")) {

show\_compose = show\_category + Comma + show\_category\_s;

}

 

DAOimpl

if(!recommend\_flag.equals("")){

f.append(" and (bean.recommend\_flag='"+recommend\_flag+"')");

}

if(!show\_compose.equals(""))

{

f.append(" and (bean.show\_category like '%"+show\_compose+"%')");

}

DAOimpl中因前段Freemaker传过来的参数初始化为空字符，所有肯定就不是null ，就只需做空字符判断，