Created
November 17, 2015 22:50
-
-
Save benelog/7b8c0fe70bdcc38f1c53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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