query string contains string

In the MySQL of jdbc, you don't need to write the comparator, for example:

    select * from t_user t where find_in_set('1',t.username) ;

    Of course, you can also use it like this:

    select * from t_user t where find_in_set('1',t. username)>0

    and in the HQL statement of hibernate, it must be used like this:

    from User t where find_in_set('1',t.username)>0

The value of userName contains multiple "11,125,52";
tringBuffer sql=new StringBuffer();
sql.append("from User t wheret.companyId=0 "); 
String[] username={"11,12,55,4"}; sql.append(" and ( ");
 for(int i=0;i<username.length;i++){if(i==0){

 
 sql.append(" find_in_set('"+username[i]+"',t.username)>0");
 }else{
 sql.append(" or find_in_set('"+username[i]+"',t.username)>0");
 }
 }
 sql.append( " ) " );
     that is, '>0' must be included, otherwise an error will be reported. 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326809151&siteId=291194637