我有以下查询:
ObjectMapper
这个查询实际上做的是 -
public class PlaylistActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private SongsAdapter songsAdapter;
SongsManager songsManager;
String MEDIA_PATH = Environment.getExternalStorageDirectory() + "";
ArrayList<HashMap<String, String>> songList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_playlist);
recyclerView=(RecyclerView)findViewById(R.id.playlistactivityrecyclerview);
songsManager=new SongsManager();
songList =songsManager.getPlayList(MEDIA_PATH);
songsAdapter=new SongsAdapter(songList);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
recyclerView.setAdapter(songsAdapter);
Toast.makeText(getApplicationContext(),"Hi",Toast.LENGTH_LONG).show();
}
}
public class SongsAdapter extends RecyclerView.Adapter<SongsAdapter.MyViewHolder>{
ArrayList<HashMap<String, String>> songList;
public SongsAdapter(ArrayList<HashMap<String, String>> songList)
{
this.songList = songList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.textView.setText(songlist.get(position).get("file_name"));
}
}
@Override
public int getItemCount() {
return songList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView textView;
public MyViewHolder(View itemView){
super(itemView);
textView=(TextView)itemView.findViewById(R.id.listitemtextview);
}
@Override
public void onClick(View v) {
}
}
}
等问题
这非常有效,但在第一种情况下,如果public class SongsManager {
public ArrayList<HashMap<String, String>> getPlayList(String rootPath) {
ArrayList<HashMap<String, String>> fileList = new ArrayList<>();
try {
File rootFolder = new File(rootPath);
File[] files = rootFolder.listFiles(); //here you will get NPE if directory doesn't contains any file,handle it like this.
for (File file : files) {
if (file.isDirectory()) {
if (getPlayList(file.getAbsolutePath()) != null) {
fileList.addAll(getPlayList(file.getAbsolutePath()));
} else {
break;
}
} else if (file.getName().endsWith(".mp3")) {
HashMap<String, String> song = new HashMap<>();
song.put("file_path", file.getAbsolutePath());
song.put("file_name", file.getName());
fileList.add(song);
}
}
return fileList;
} catch (Exception e) {
return null;
}
}
}
为2,我想要排除产品。
任何人都可以告诉我如何实现这个目标
SQLFIDDLE
http://sqlfiddle.com/#!9/9bb584/1
由于
答案 0 :(得分:0)
对于那些在将来遇到类似问题的人,
实际上将查询修改为此。谢谢@Solarflare
SELECT
prod.*,
details.specification,
details.warrantyinfo
FROM
Products prod
INNER JOIN ProductDetails details
ON details.product_id = prod.id
WHERE
prod.is_approved = '1'
AND prod.is_active = '1'
AND prod.is_deleted = '0'
ORDER BY
prod.created_at > '2017-08-14' AND prod.`listing_type`>2 DESC,
IF(prod.created_at > '2017-08-14' AND prod.`listing_type`>2, prod.created_at, FIELD(prod.listing_type,2,3,4,5,6)) DESC,
prod.is_featured DESC
这完美无瑕。