CriteriaBuilder(Hibernate)

时间:2015-09-14 13:01:44

标签: java spring hibernate

我想编写自定义Hibernate查询。

   restrictions.add(builder.equal("type", a.getType()));

我知道怎么写"等于"

List<Integer> integers = new ArrayList();
integers.add(1);
integers.add(2);
integers.add(3);
restrictions.add(builder (what to write here???));

但是如何在&#34; 中编写&#34;

restrictions.add(ad.get("counts").in(integers));

更新:

感谢 Roger Gustavsson

解决方案:

// Method for sending files using multiparting......
public static String sendJsonWithFile(Activity mActivity, ArrayList<String> mImagePaths, String jsonString, String URL)
{
    Log.e("json", jsonString);
    String res = "";
    try
    {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(URL);
        String boundary = "*****" + Long.toString(System.currentTimeMillis()) + "*****";
        boundary = "--" + boundary;
        httppost.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    StringBody stringBody = new StringBody(jsonString);

    reqEntity.addPart("formstring", stringBody);

    for (int i = 0; i < mImagePaths.size(); i++)
    {
        String imagePath = mImagePaths.get(i);
        if (mImagePaths != null && mImagePaths.size() > 0)
        {

            byte[] filebytes = FileUtils.readFileToByteArray(new File(imagePath));

            ByteArrayBody filebodyImage = new ByteArrayBody(filebytes, "image");
            Log.e("file path=", filebodyImage.toString());

            reqEntity.addPart("image", filebodyImage);

        }

    }

    httppost.setEntity(reqEntity);
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    if (resEntity != null)
    {
        res = EntityUtils.toString(resEntity);
        System.out.println(res);
    }

    if (resEntity != null)
    {
        resEntity.consumeContent();
    }
    httpclient.getConnectionManager().shutdown();
}
catch (UnsupportedEncodingException e)
{
    res = "UnsupportedEncodingException";
    e.printStackTrace();
}
catch (ClientProtocolException e)
{
    res = "ClientProtocolException";
    e.printStackTrace();
}
catch (FileNotFoundException e)
{
    res = "FileNotFoundException";
    e.printStackTrace();
}
catch (IOException e)
{
    res = "IOException";
    e.printStackTrace();
}
catch (Exception e)
{
    res = "Exception";
    e.printStackTrace();
}
return res;
}

另一个问题:

如何编写isNotNull一些字段?例如,A类有一组B类; 我需要检查A是否至少有一个B类?

0 个答案:

没有答案