Android builds MVC architecture for the first time

Insert picture description here

1_database

2_server

  1. Simple setup on the server side

  2. Use json, import the jar package and copy this content and open the Baidu
    Netdisk mobile App, which is more convenient to operate. Extraction code: 3afj
    build a folder in the project and paste it into it

  3. Conversion between json and list:

import com.alibaba.fastjson.JSON;

import java.util.List;

public class JsonListUtil {
    
    
   /**
    * List<T> 转 json字符串
    */
   public static <T> String listToJson(List<T> ts) {
    
    
      return JSON.toJSONString(ts);
   }

   /**
    * json 字符串转 List<T>
    */
   public static <T> List<T> jsonToList(String jsonString) {
    
    
      @SuppressWarnings("unchecked")
      List<T> ts = (List<T>) JSON.parse(jsonString);
      return ts;
   }
}

3_Client

3.1_ Import okhttp dependency

  1. Network request protocol:
    will be <uses-permission android:name="android.permission.INTERNET" />added to Manifest.xml
    Insert picture description here

  2. Query dependent statement
    Enter the okhttp official website and copy the following statement
    Insert picture description here

  3. Import dependency
    Switch Android to project, open build.gradle under app project to add dependency
    Insert picture description here

  4. sync
    Insert picture description here
    Note: URL cannot use localhost instead of local ip address

Guess you like

Origin blog.csdn.net/qq_43907296/article/details/114988545