草庐IT

android - 如何在android中的两个不同日期从MySQL获取数据并在多列ListView中显示

coder 2023-12-15 原文

我正在将三个(客户名称、开始日期和结束日期)值传递给 PHP 文件,但背后的问题是,我当时没有传递三个值,只有一个值(客户名称)移动到 PHP 文件。并且如何在多列列表中显示日期

java文件:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.customer_repo);

    // Permission StrictMode
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    setCurrentDateOnView();
    addListenerOnButton();

    cus_name = (Spinner) findViewById(R.id.spinner1);//customer spinner
    created_date1 = (TextView) findViewById(R.id.tvDate);
    created_date2 = (TextView) findViewById(R.id.tvDate2);

    //spinner for customer name
    cus_name = (Spinner) findViewById(R.id.spinner1);
    adapter = new ArrayAdapter<String>(this, R.layout.spinner_custo_report, R.id.txt, listItems);
    cus_name.setAdapter(adapter);
    cus_name.setAdapter(new NothingSelectedSpinnerAdapter(adapter, R.layout.custo_rep_nothingselect, this));


    Button submit = (Button) findViewById(R.id.loadbtn);
    assert submit != null;
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            cus_names = cus_name.getSelectedItem().toString();
            createddate = created_date1.getText().toString();
            created_date = created_date2.getText().toString();
            String url_server = "http://192.168.1.13:8090/Vaari_services/getCustomerReportData.php";
            new BackgroundTask_Asycn().execute(url_server);
        }
    });
}


// Class with extends AsyncTask class
//product stock one
private class BackgroundTask_Asycn  extends AsyncTask<String, Void, Void> {

    // Required initialization
    private final HttpClient Client = new DefaultHttpClient();
    private String Content;
    private String Error = null;
    private ProgressDialog Dialog = new ProgressDialog(Customer_Repo.this);
    String cus_name ="";
    String created_date1 ="";
    String created_date2 ="";
    int sizeData = 0;
    TextView pro_stock1 = (TextView)findViewById(R.id.tvDate);
    Spinner customerName = (Spinner)findViewById(R.id.spinner1);
    TextView createddate1 = (TextView) findViewById(R.id.tvDate);
    TextView createddate2 = (TextView) findViewById(R.id.tvDate2);

    protected void onPreExecute() {
        // NOTE: You can call UI Element here.
        //Start Progress Dialog (Message)

        Dialog.setMessage("Please wait..");
        Dialog.show();

        try{
            // Set Request parameter product one
            cus_name +="&" + URLEncoder.encode("cus_name", "UTF-8") + "="+customerName.getSelectedItem();
            //created_date1 +="&" + URLEncoder.encode("created_date1", "UTF-8") + "="+createddate1.getText();
            //created_date2 +="&" + URLEncoder.encode("created_date2", "UTF-8") + "="+createddate2.getText();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    // Call after onPreExecute method
    protected Void doInBackground(String... urls) {
        /************ Make Post Call To Web Server ***********/
        BufferedReader reader=null;

        // Send data
        try
        {
            // Defined URL  where to send data
            URL url = new URL(urls[0]);
            // Send POST data request
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(cus_name);
            //wr.write(created_date1);
            //wr.write(created_date2);
            wr.flush();
            // Get the server response
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder sb = new StringBuilder();
            String line = null;
            // Read Server Response
            while((line = reader.readLine()) != null)
            {
                // Append server response in string
                sb.append(line + "");
            }
            // Append Server Response To Content String
            Content = sb.toString();
        }
        catch(Exception ex)
        {
            Error = ex.getMessage();
        }
        finally
        {
            try
            {
                reader.close();
            }
            catch(Exception ex) {}
        }
        return null;
    }

    protected void onPostExecute(Void unused) {
        // NOTE: You can call UI Element here.

        // Close progress dialog
        Dialog.dismiss();

        if (Error != null) {

            pro_stock1.setText("Output : "+Error);

        } else {

            // Show Response Json On Screen (activity)
            pro_stock1.setText( Content );

            /****************** Start Parse Response JSON Data *************/

            String OutputData = "";
            JSONObject jsonResponse;

            try {

                /****** Creates a new JSONObject with name/value mappings from the JSON string. ********/
                jsonResponse = new JSONObject(Content);


                /***** Returns the value mapped by name if it exists and is a JSONArray. ***/
                /*******  Returns null otherwise.  *******/
                JSONArray jsonMainNode = jsonResponse.optJSONArray("customer_repo");

                /*********** Process each JSON Node ************/

                int lengthJsonArr = jsonMainNode.length();

                for(int i=0; i < lengthJsonArr; i++)
                {
                    /****** Get Object for each JSON node.***********/
                    JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);

                    /******* Fetch node values **********/
                    String Stock1 = jsonChildNode.optString("created_date").toString();
                    String Stock2 = jsonChildNode.optString("order_no").toString();
                    String Stock3 = jsonChildNode.optString("product").toString();
                    OutputData += Stock1 + Stock2 + Stock3;


                }
                /****************** End Parse Response JSON Data *************/

                //Show Parsed Output on screen (activity)
                pro_stock1.setText( OutputData );

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

}

这是问题的开始,如何传递我必须做的事情。如果有任何选择

cus_name +="&" + URLEncoder.encode("cus_name", "UTF-8") + "="+customerName.getSelectedItem();
//created_date1 +="&" + URLEncoder.encode("created_date1", "UTF-8") + "="+createddate1.getText();
//created_date2 +="&" + URLEncoder.encode("created_date2", "UTF-8") + "="+createddate2.getText();

这是正确的方法

    wr.write(cus_name);
   //wr.write(created_date1);
   //wr.write(created_date2);

XML 文件:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#282828"
    android:orientation="vertical"
    android:padding="10dp">

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#282828"
        android:padding="10dp"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical"
            android:padding="2dp">

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp">

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:gravity="center_horizontal"
                    android:text="CUSTOMER ORDER REPORT"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#00aa55"
                    android:textSize="30dp"
                    android:textStyle="bold" />

            </TableRow>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical"
            android:padding="5dp">

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="2dp">

                <Spinner
                    android:id="@+id/spinner1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="1dp"
                    android:textSize="20sp" />

            </TableRow>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical"
            android:padding="2dp">

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="2dp">

                <Button
                    android:id="@+id/btnChangeDate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/datepicker_btn"
                    android:padding="5dp"
                    android:text="FROM DATE"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <Button
                    android:id="@+id/btnChangeDate2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:background="@drawable/datepicker_btn"
                    android:padding="10dp"
                    android:text="TO DATE"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tvDate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#FFFFFF"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tvDate2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#FFFFFF"
                    android:textStyle="bold" />


            </TableRow>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical"
            android:padding="2dp">

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="2dp">


                <Button
                    android:id="@+id/loadbtn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btnbg"
                    android:padding="10dp"
                    android:text="LOAD"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:textStyle="bold" />
            </TableRow>
        </LinearLayout>

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="fill_parent"
            android:layout_height="match_parent">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <!-- table format-->
                <LinearLayout
                    android:id="@+id/relativeLayout1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorCell">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="ORDER DATE"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="2"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="ORDER NO"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1.5"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="PRODUCT NAME"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="ORDER QTY"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />


                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="SUPPLIED QTY"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />


                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="SUPPLIED DATE"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />


                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="BALANCE QTY"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:textColor="#FFFFFF"
                        android:textStyle="bold" />


                </LinearLayout>

            </ScrollView>
        </HorizontalScrollView>

        <ListView
            android:id="@+id/listview_customername"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@null" />
    </TableLayout>
</RelativeLayout>

PHP 文件:

    <?php
    require "db_config.php";

    $cus_name= $_POST["cus_name"];
    $created_date1= $_POST['created_date1'];
    $created_date2= $_POST['created_date2'];

    $sql="select oc.created_date,oc.order_no,ot.product,ot.order_qty,ot.qty_supply as Supplied_qty,ot.sup_date as issue_date,ot.bal_qty from order_creation oc inner join order_tran ot on oc.order_no=ot.orderno where oc.cus_name='".$cus_name."' and convert(datetime,ot.sup_date,104) between convert(datetime,'".$created_date1."') and convert(datetime, '".$created_date2."') and ot.product is not null order by ot.product,oc.order_no,ot.bal_qty desc";

    $stmt=sqlsrv_query($conn,$sql );
    if($stmt===false) 
    {
        die(print_r(sqlsrv_errors(),true));
    }
    while($row=sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) 
    {
      $json['customer_repo'][]=$row;
    }
    sqlsrv_free_stmt($stmt);
    echo json_encode($json);

?>

最佳答案

对数据集使用数据模型类而不是 HashMap 。

public class CustomerData {
    String createdAt;
    String orderNo;

    public CustomerData(String createdAt, String orderNo) {
        this.createdAt = createdAt;
        this.orderNo = orderNo;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public String getOrderNo() {
        return orderNo;
    }
}

然后像这样修改你的代码

 public void ShowData() {
// listView1
    final ListView lisView1 = (ListView) findViewById(R.id.listview_customername);

    Spinner cus_name = (Spinner) findViewById(R.id.spinner1);
    TextView created_date1 = (TextView) findViewById(R.id.tvDate);
    TextView created_date2 = (TextView) findViewById(R.id.tvDate2);


    String url = "http://192.168.1.13:8090/Vaari_services/getCustomerReportData.php";

    // Paste Parameters
    //List<NameValuePair> params = new ArrayList<NameValuePair>();

    new GetCustomerDataTask().execute(url);

}
private class GetCustomerDataTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        // params comes from the execute() call: params[0] is the url.
        try {
            return downloadUrl(urls[0]);
        } catch (IOException e) {
            return "Unable to retrieve web page. URL may be invalid.";
        }
    }
    // onPostExecute displays the results of the AsyncTask.
    @Override
    protected void onPostExecute(String result) {
        parseData(result);
    }
}


  // Given a URL, establishes an HttpUrlConnection and retrieves
 // the web page content as a InputStream, which it returns as
// a string.
private String downloadUrl(String myurl) throws IOException {
    InputStream is = null;
    // Only display the first 500 characters of the retrieved
    // web page content.
    int len = 500;

    List<NameValuePair> params = new ArrayList<>();

    params.add(new BasicNameValuePair("cus_name", cus_names);
    params.add(new BasicNameValuePair("created_date1", createddate);
    params.add(new BasicNameValuePair("created_date2", created_date);



    try {
        URL url = new URL(myurl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        // Starts the query
        conn.connect();
        int response = conn.getResponseCode();
        Log.d(DEBUG_TAG, "The response is: " + response);
        is = conn.getInputStream();

        // Convert the InputStream into a string
        String contentAsString = readIt(is, len);
        return contentAsString;

        // Makes sure that the InputStream is closed after the app is
        // finished using it.
    } finally {
        if (is != null) {
            is.close();
        }
    }
}


public void parseData(String response){
    try {
        JSONObject parentObject = new JSONObject(response);
        JSONArray data = parentObject.getJSONArray("customer_repo");

        //JSONArray data = new JSONArray(getJSONUrl(url,params));
        ArrayList<CustomerData> customerArrayList = new ArrayList<CustomerData>();
        for (int i = 0; i < data.length(); i++) {
            JSONObject c = data.getJSONObject(i);
            String createdDate = c.getString("created_date");
            String orderNo = c.getString("created_date");
            customerArrayList.add(new CustomerData(createdDate, orderNo));
        }

        imageAdapter = new ImageAdapter(this, customerArrayList);
        lisView1.setAdapter(imageAdapter);
        imageAdapter.notifyDataSetChanged();
        registerForContextMenu(lisView1);


    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

   public class ImageAdapter extends BaseAdapter {
    private Context context;
    ArrayList<CustomerData> customerDataArrayList;

    public ImageAdapter(Context c,ArrayList<CustomerData>   customerDataArrayList) {
        // TODO Auto-generated method stub
        context = c;
        this.customerDataArrayList= customerDataArrayList;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return customerDataArrayList.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return customerDataArrayList.get(position);
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_cus_report, null);
        }

        // created date
        TextView txtOrdDate = (TextView) convertView.findViewById(R.id.ColOrDate);
        txtOrdDate.setPadding(10, 0, 0, 0);
        txtOrdDate.setText(customerDataArrayList.get(position).getCreatedAt() + ".");
        txtOrdDate.setTextSize(18);
        txtOrdDate.setTextColor(Color.parseColor("#FFFFFF"));

        // Oredr No
        TextView txtOrdNo = (TextView) convertView.findViewById(R.id.ColOrNo);
        txtOrdNo.setPadding(5, 0, 0, 0);
        txtOrdNo.setText(customerDataArrayList.get(position).getOrderNo());
        txtOrdNo.setTextSize(18);
        txtOrdNo.setTextColor(Color.parseColor("#FFFFFF"));

        return convertView;

    }

}

同时发布你的getJSONUrl方法

关于android - 如何在android中的两个不同日期从MySQL获取数据并在多列ListView中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37983162/

有关android - 如何在android中的两个不同日期从MySQL获取数据并在多列ListView中显示的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时

  3. ruby - 如何在 Ruby 中顺序创建 PI - 2

    出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

  4. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  5. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题

  6. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  7. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  8. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  9. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  10. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

随机推荐