Java??????????
???????????? ???????[ 2016/4/19 10:56:36 ] ??????????????????? ?????
???????????????leader??????????????????????????????????????????or?????????????????for????????????ò?????false????????????or???????????????????true??????????????ζ???????????????or?????????????????????or???????????????????SQL????β?????????or????????????????????????????findUserInfo??????????????????strategy??1??????????????strategy??2??????????????
?????????????????????????·????
????public class Test {
????public static void main(String[] args) throws Exception {
????QueryUtil query = new QueryUtil();
????query.findUserInfo(new String[] { "Tom"?? "Jim"?? "Anna" }?? 2);
????}
????}
???????????????????????????????????SQL????????????????????????????????
??????????????leader???????????????????????????????????????????????????????????
????“??????д?????findUserInfo??????????????????????????????????????????????????????????е????????????????????????????????” ???leader?????????????????????ò??????????????????????????????????????????????????????С?
???????????????????????????????????????ò??????????????
?????????????????????
????public interface Strategy {
????String getSQL(String[] usernames);
????}
????????????????????????????????????????SQL?????????????????????У?
public class Strategy1 implements Strategy {
@Override
public String getSQL(String[] usernames) {
StringBuilder sql = new StringBuilder("select * from user_info where ");
for (String user : usernames) {
sql.append("username = '");
sql.append(user);
sql.append("' or ");
}
sql.delete(sql.length() - " or ".length()?? sql.length());
return sql.toString();
}
}
public class Strategy2 implements Strategy {
@Override
public String getSQL(String[] usernames) {
StringBuilder sql = new StringBuilder("select * from user_info where ");
boolean needOr = false;
for (String user : usernames) {
if (needOr) {
sql.append(" or ");
}
sql.append("username = '");
sql.append(user);
sql.append("'");
needOr = true;
}
return sql.toString();
}
}
????????QueryUtil??findUserInfo?????????????????Strategy????????????????Strategy??getSQL???????????????SQL????????????????
public class QueryUtil {
public void findUserInfo(String[] usernames?? Strategy strategy) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test"?? "root"??
"123456");
Statement stat = conn.createStatement();
String sql = strategy.getSQL(usernames);
System.out.println(sql);
ResultSet resultSet = stat.executeQuery(sql);
while (resultSet.next()) {
// ?????????????????????
}
// ?????????????????????????????????????
}
}
??????????????????findUserInfo???????????????????????????????????????????
????public class Test {
????public static void main(String[] args) throws Exception {
????QueryUtil query = new QueryUtil();
????query.findUserInfo(new String[] { "Tom"?? "Jim"?? "Anna" }?? new Strategy1());
????query.findUserInfo(new String[] { "Jac"?? "Joe"?? "Rose" }?? new Strategy2());
????}
????}
???????????SQL???????????????????????
????select * from user_info where username = 'Tom' or username = 'Jim' or username = 'Anna'
????select * from user_info where username = 'Jac' or username = 'Joe' or username = 'Rose'
??????ò???????????????????????????????????????????????????μ????????????????????
???????????????????????????????????????????????????滻????????????仯????????????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????