Skip to content

Instantly share code, notes, and snippets.

@benelog
Created November 17, 2015 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benelog/7b8c0fe70bdcc38f1c53 to your computer and use it in GitHub Desktop.
Save benelog/7b8c0fe70bdcc38f1c53 to your computer and use it in GitHub Desktop.
import static org.apache.commons.lang.StringUtils.*
class SqlMap {
public static String buildSelectSql(User user) {
StringBuilder sql = new StringBuilder();
sql.append("""
SELECT name, address
FROM user
WHERE 1=1
""");
if (isNotEmpty(user.getName())) {
sql.append("""
AND name = :name
""");
}
if (isNotEmpty(user.getAddress())) {
sql.append("""
AND address = :address
""");
}
return sql.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment