Android Contacts的使用(三)

2023-10-21 14:59
文章标签 android 使用 contacts

本文主要是介绍Android Contacts的使用(三),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Working With Android Contacts

Gluing it together 整合

To put this together into an application there are a few glue pieces that need to be setup along with creating classes to manage accessing the data. First we need to create a set of classes to hold the data. Also we'll create a class to handle 2.0 API calls and a class to handle 1.6 and earlier API calls. There's also a wrapper class that determines and loads the proper class.

需把整合类一起放在程序里,同时创建类来管理访问这些数据。(该处实在是翻译不通)。首先,我们需要创建一个类用来保存数据。此外,我们将创建一个类用来处理2.0API 调用和一个类用来处理1.6 或更早的 API 调用。还有一个包装类,用来确定并加载适当的类。 

Contact Data Classes 联系人数据类

The contact classes are a series of classes to hold a list of contacts. The list is stored in the class ContactList that maintains an ArrayList of Contacts. The Contact objects are represented in the Contact class. The contact class stores all the data from the Android contact record. In addition to the ContactList and Contact classes there are specialized classes to represent some of the record data.

Contact类是一系列保持名片夹列表的类。该类存储在ContactList类中,此类维护着联系人列表。Contact类表示联系人对象,该类保存着所有从Android查询出的联系人数据。另外,在ContactList和Contact类中,有特定的类来表示某些记录的信息。


 

We will create classes to represent the address, email, instant messenger, phone number, and organization(s). Most of these classes are mere data storage classes with variables and getter/setters.

我们将创建一个实体类来表示地址、email、即时通讯、电话号码、组织等信息。该类大部分数据是单纯的变量,和一些getter/setters方法。


ContactList

The ContactList class is a very basic class designed to hold an ArrayList of instances of the Contact class below. We've left this class very plain and ready to be expanded to suit your needs.

ContactList是一个基类,设计一个ArrayList数组用来存储Contact实例。这样降低了耦合度,可以随时扩大以满足需求。

复制代码
  
package com.test;

import java.util.ArrayList;

public class ContactList {
private ArrayList<Contact> contacts = new ArrayList<Contact>();

public ArrayList<Contact> getContacts() {
return contacts;
}

public void setContacts(ArrayList<Contact> contacts) {
this.contacts = contacts;
}

public void addContact(Contact contact) {
this.contacts.add(contact);
}

public ContactList() {

}

}
复制代码


Contact

The Contact class is used to store the details about each contact. There are a series of private class variables to hold this data. Singular data such as name and database ID are stored as strings. Complex data is stored either as an instance or ArrayList of data specific classes. This class is mainly getters and setters with a few methods to add to the internal ArrayLists. 

Contact类用来存储每个联系人的详细信息。该类定义了一些私有变量来保存这些数据。如名称和id定义成String型,而复杂的数据侧定义成数组或实例。这个类主要是生成一个getters和setters方法以便添加到数组中。

复制代码
  
package com.test;

import java.util.ArrayList;


public class Contact {
private String id;
private String displayName;
private ArrayList<Phone> phone;
private ArrayList<Email> email;
private ArrayList<String> notes;
private ArrayList<Address> addresses = new ArrayList<Address>();
private ArrayList<IM> imAddresses;
private Organization organization;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public ArrayList<Phone> getPhone() {
return phone;
}
public void setPhone(ArrayList<Phone> phone) {
this.phone = phone;
}
public void addPhone(Phone phone) {
this.phone.add(phone);
}
public ArrayList<Email> getEmail() {
return email;
}
public void setEmail(ArrayList<Email> email) {
this.email = email;
}
public void addEmail(Email email) {
this.email.add(email);
}
public ArrayList<String> getNotes() {
return notes;
}
public void setNotes(ArrayList<String> notes) {
this.notes = notes;
}
public void AddNotes(String notes){
this.notes.add(notes);
}
public ArrayList<Address> getAddresses() {
return addresses;
}
public void setAddresses(ArrayList<Address> addresses) {
this.addresses = addresses;
}
public void addAddress(Address address) {
this.addresses.add(address);
}
public ArrayList<IM> getImAddresses() {
return imAddresses;
}
public void setImAddresses(ArrayList<IM> imAddresses) {
this.imAddresses = imAddresses;
}
public void addImAddresses(IM imAddr) {
this.imAddresses.add(imAddr);
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
}
复制代码


Address

The Address class is the only class in the ContactList framework that actually does any work. Due to differences in data storage between 1.x and 2.0 versions of Android the Address class has to determine if the input address is free-form from 1.x or was input from the formatted data structure from 2.0. Android 2.0 has individual data columns for PO-Box, street, city, region, postal code, country while 1.x was just a text field with the entire address. This is handled in the toString() method that returns a free-form address from either input type. Unfortunately when using Android 1.x all the individual address getters will return null.

地址类是联系人列表框架中负责所有操作的唯一类。鉴于1.x 和2.0 版本中数据存储不同,Android类必须确认输入的地址是1.x 以上的自由格式还是2.0的格式化数据结构。Android 2.0 有单独的数据列给PO-Box,street,city,region,postal code,country 而1.x整个地址中只是一个文本域,并在toString()方法中处理,该方法返回一个没有格式的地址或者输入类型。不幸的是使用Android1.x 所有的单独地址获取都将返回null 。

复制代码
  
package com.test;

public class Address {
private String poBox;
private String street;
private String city;
private String state;
private String postalCode;
private String country;
private String type;
private String asString = "";

public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPoBox() {
return poBox;
}
public void setPoBox(String poBox) {
this.poBox = poBox;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String toString() {
if (this.asString.length() > 0) {
return(this.asString);
}
else {
String addr
= "";
if (this.getPoBox() != null) {
addr
= addr + this.getPoBox() + "n";
}
if (this.getStreet() != null) {
addr
= addr + this.getStreet() + "n";
}
if (this.getCity() != null) {
addr
= addr + this.getCity() + ", ";
}
if (this.getState() != null) {
addr
= addr + this.getState() + " ";
}
if (this.getPostalCode() != null) {
addr
= addr + this.getPostalCode() + " ";
}
if (this.getCountry() != null) {
addr
= addr + this.getCountry();
}
return(addr);
}
}

public Address(String asString, String type) {
this.asString = asString;
this.type = type;
}

public Address(String poBox, String street, String city, String state,
String postal, String country, String type) {
this.setPoBox(poBox);
this.setStreet(street);
this.setCity(city);
this.setState(state);
this.setPostalCode(postal);
this.setCountry(country);
this.setType(type);
}
}
复制代码


 

Email

Another getter/setter and data storage class. The email class stores the email address and address type (work, home, etc).

另一个生成getter/setter的数据存储类。该类存储的是email的邮件地址和地址类型(工作、家庭等)。

复制代码
  
package com.test;

public class Email {
private String address;
private String type;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getType() {
return type;
}
public void setType(String t) {
this.type = t;
}

public Email(String a, String t) {
this.address = a;
this.type = t;
}
}
复制代码


 

IM

Class to hold instant messenger data. 该类用来保存即时消息数据。

复制代码
  
package com.test;

public class IM {
private String name;
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

public IM(String name, String type) {
this.name = name;
this.type = type;
}
}
复制代码



Organization

Class to hold the contacts organizational data. 该类用来保存联系人组织数据。

复制代码
  
package com.test;

public class Organization {
private String organization = "";
private String title = "";
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

public Organization() {

}
public Organization(String org, String title) {
this.organization = org;
this.title = title;
}
}
复制代码


Phone

Class to hold the phone records.  该类用来保存电话记录。

复制代码
  
package com.test;

public class Phone {
private String number;
private String type;

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Phone(String n, String t) {
this.number = n;
this.type = t;
}
}
复制代码

 

Wrapper class 封装类

The wrapper class below is what will be invoked by applications. This class will determine the API level running on the device/emulator and load the correct class created on the next pages. To determine the correct Android API running the Build.VERSION.SDK variable is queried. This version code is then compared against the Eclair (2.0) version code stored in Build.VERSION_CODES.ECLAIR. Finally the proper API class is loaded.

下面的这个封装类是由应用程序所调用的。该类确认运行在设备/模拟器上API的版本。要确认正确的运行着的Android API需要访问VERSION.SDK变量。取得版本号然后跟存于Build.VERSION_CODES.ECLAIR的Eclair(2.0)版本号相比较。最好加载相应的API。

复制代码
  
package com.test;

import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.os.Build;

public abstract class ContactAPI {
private static ContactAPI api;

public static ContactAPI getAPI() {
if (api == null) {
String apiClass;
if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.ECLAIR) {
apiClass
= "com.highercollaboration.android.ContactAPI.ContactAPISdk5";
}
else {
apiClass
= "com.highercollaboration.android.ContactAPI.ContactAPISdk3";
}

try {
Class
<? extends ContactAPI> realClass = Class.forName(apiClass).
asSubclass(ContactAPI.
class);
api
= realClass.newInstance();
}
catch (Exception e) {
throw new IllegalStateException(e);
}

}
return api;
}

public abstract Intent getContactIntent();

public abstract ContactList newContactList();

public abstract Cursor getCur();
public abstract void setCur(Cursor cur);

public abstract ContentResolver getCr();
public abstract void setCr(ContentResolver cr);

}
复制代码


2.0 Data access class 2.0数据访问类

This class takes what was covered on page 1 of the tutorial about the Android 2.0 Contact API and turns it into a class. This class extends and will be invoked by the wrapper class created previously.

这个类在前面的Android Contacts的使用(一)中介绍了关于Android 2.0 联系人API 的教程并把他封装成一个类。这个类扩展并由先前建立的封装类调用。

复制代码
  
package com.test;
import java.util.ArrayList;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.provider.ContactsContract;

public class ContactAPISdk5 extends ContactAPI {

private Cursor cur;
private ContentResolver cr;


public Cursor getCur() {
return cur;
}

public void setCur(Cursor cur) {
this.cur = cur;
}

public ContentResolver getCr() {
return cr;
}

public void setCr(ContentResolver cr) {
this.cr = cr;
}

public Intent getContactIntent() {
return(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI));
}

public ContactList newContactList() {
ContactList contacts
= new ContactList();
String id;

this.cur = this.cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (this.cur.getCount() > 0) {
while (cur.moveToNext()) {
Contact c
= new Contact();
id
= cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
c.setId(id);
c.setDisplayName(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
c.setPhone(
this.getPhoneNumbers(id));
}
c.setEmail(
this.getEmailAddresses(id));
c.setNotes(
this.getContactNotes(id));
c.setAddresses(
this.getContactAddresses(id));
c.setImAddresses(
this.getIM(id));
c.setOrganization(
this.getContactOrg(id));
contacts.addContact(c);
}
}
return(contacts);
}

public ArrayList<Phone> getPhoneNumbers(String id) {
ArrayList
<Phone> phones = new ArrayList<Phone>();

Cursor pCur
= this.cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
phones.add(
new Phone(
pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))
, pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE))
));

}
pCur.close();
return(phones);
}

public ArrayList<Email> getEmailAddresses(String id) {
ArrayList
<Email> emails = new ArrayList<Email>();

Cursor emailCur
= this.cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = ?",
new String[]{id}, null);
while (emailCur.moveToNext()) {
// This would allow you get several email addresses
Email e = new Email(emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA))
,emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE))
);
emails.add(e);
}
emailCur.close();
return(emails);
}

public ArrayList<String> getContactNotes(String id) {
ArrayList
<String> notes = new ArrayList<String>();
String where
= ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters
= new String[]{id,
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
Cursor noteCur
= this.cr.query(ContactsContract.Data.CONTENT_URI, null, where, whereParameters, null);
if (noteCur.moveToFirst()) {
String note
= noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
if (note.length() > 0) {
notes.add(note);
}
}
noteCur.close();
return(notes);
}

public ArrayList<Address> getContactAddresses(String id) {
ArrayList
<Address> addrList = new ArrayList<Address>();

String where
= ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters
= new String[]{id,
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};

Cursor addrCur
= this.cr.query(ContactsContract.Data.CONTENT_URI, null, where, whereParameters, null);
while(addrCur.moveToNext()) {
String poBox
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX));
String street
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
String city
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
String state
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
String postalCode
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
String country
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
String type
= addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));
Address a
= new Address(poBox, street, city, state, postalCode, country, type);
addrList.add(a);
}
addrCur.close();
return(addrList);
}

public ArrayList<IM> getIM(String id) {
ArrayList
<IM> imList = new ArrayList<IM>();
String where
= ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters
= new String[]{id,
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};

Cursor imCur
= this.cr.query(ContactsContract.Data.CONTENT_URI, null, where, whereParameters, null);
if (imCur.moveToFirst()) {
String imName
= imCur.getString(imCur.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA));
String imType;
imType
= imCur.getString(imCur.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE));
if (imName.length() > 0) {
IM im
= new IM(imName, imType);
imList.add(im);
}
}
imCur.close();
return(imList);
}

public Organization getContactOrg(String id) {
Organization org
= new Organization();
String where
= ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters
= new String[]{id,
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};

Cursor orgCur
= this.cr.query(ContactsContract.Data.CONTENT_URI, null, where, whereParameters, null);

if (orgCur.moveToFirst()) {
String orgName
= orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA));
String title
= orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE));
if (orgName.length() > 0) {
org.setOrganization(orgName);
org.setTitle(title);
}
}
orgCur.close();
return(org);
}

}
复制代码


1.x Data access class 1.x数据访问类

This class is made up of the code explained covering version 1.x of the Android contact API. As with the 2.0 class this class extends the ContactAPI wrapper class and will be invoked by it if the 1.x version of Android is in use.

这个类由Android 1.0 联系人版本介绍的代码组成。正如2.0中,这个类扩展了ContactAPI封装类,并且封装类调用这个类,当然前提是使用1.x 版本。

复制代码
  
package com.test;

import java.util.ArrayList;

import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.provider.Contacts;
import android.provider.Contacts.People;

public class ContactAPISdk3 extends ContactAPI {

private Cursor cur;
private ContentResolver cr;

public Cursor getCur() {
return cur;
}

public void setCur(Cursor cur) {
this.cur = cur;
}

public ContentResolver getCr() {
return cr;
}

public void setCr(ContentResolver cr) {
this.cr = cr;
}

public Intent getContactIntent() {
return(new Intent(Intent.ACTION_PICK, People.CONTENT_URI));
}

public ContactList newContactList() {
ContactList contacts
= new ContactList();
String id
="";

this.cur = this.cr.query(People.CONTENT_URI,
null, null, null, null);
if (this.cur.getCount() > 0) {
while (cur.moveToNext()) {
Contact c
= new Contact();
id
= cur.getString(cur.getColumnIndex(People._ID));
c.setId(id);
c.setDisplayName(cur.getString(cur.getColumnIndex(People.DISPLAY_NAME)));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(People.PRIMARY_PHONE_ID))) > 0) {
c.setPhone(
this.getPhoneNumbers(id));
}
c.setEmail(
this.getEmailAddresses(id));
ArrayList
<String> notes = new ArrayList<String>();
notes.add(cur.getString(cur.getColumnIndex(People.NOTES)));
c.setNotes(notes);
c.setAddresses(
this.getContactAddresses(id));
c.setImAddresses(
this.getIM(id));
c.setOrganization(
this.getContactOrg(id));
contacts.addContact(c);
}
}
return(contacts);
}

public ArrayList<Phone> getPhoneNumbers(String id) {
ArrayList
<Phone> phones = new ArrayList<Phone>();

Cursor pCur
= this.cr.query(
Contacts.Phones.CONTENT_URI,
null,
Contacts.Phones.PERSON_ID
+" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
phones.add(
new Phone(
pCur.getString(pCur.getColumnIndex(Contacts.Phones.NUMBER))
, pCur.getString(pCur.getColumnIndex(Contacts.Phones.TYPE))
));

}
pCur.close();
return(phones);
}

public ArrayList<Email> getEmailAddresses(String id) {
ArrayList
<Email> emails = new ArrayList<Email>();

Cursor emailCur
= this.cr.query(
Contacts.ContactMethods.CONTENT_EMAIL_URI,
null,
Contacts.ContactMethods.PERSON_ID
+ " = ?",
new String[]{id}, null);
while (emailCur.moveToNext()) {
// This would allow you get several email addresses
Email e = new Email(emailCur.getString(emailCur.getColumnIndex(Contacts.ContactMethods.DATA))
,emailCur.getString(emailCur.getColumnIndex(Contacts.ContactMethods.CONTENT_EMAIL_TYPE))
);
emails.add(e);
}
emailCur.close();
return(emails);
}

public ArrayList<Address> getContactAddresses(String id) {
ArrayList
<Address> addrList = new ArrayList<Address>();

String where
= Contacts.ContactMethods.PERSON_ID + " = ? AND " + Contacts.ContactMethods.KIND + " = ?";
String[] whereParameters
= new String[]{id,
Contacts.ContactMethods.CONTENT_POSTAL_ITEM_TYPE};

Cursor addrCur
= this.cr.query(Contacts.ContactMethods.CONTENT_URI, null, where, whereParameters, null);
while(addrCur.moveToNext()) {
String addr
= addrCur.getString(addrCur.getColumnIndex(Contacts.ContactMethodsColumns.DATA));
String type
= addrCur.getString(addrCur.getColumnIndex(Contacts.ContactMethodsColumns.TYPE));
Address a
= new Address(addr, type);
addrList.add(a);
}
addrCur.close();
return(addrList);
}

public ArrayList<IM> getIM(String id) {
ArrayList
<IM> imList = new ArrayList<IM>();
String where
= Contacts.ContactMethods.PERSON_ID + " = ? AND " + Contacts.ContactMethods.KIND + " = ?";
String[] whereParameters
= new String[]{id,
Contacts.ContactMethods.CONTENT_IM_ITEM_TYPE};

Cursor imCur
= this.cr.query(Contacts.ContactMethods.CONTENT_URI, null, where, whereParameters, null);
if (imCur.moveToFirst()) {
String imName
= imCur.getString(imCur.getColumnIndex(Contacts.ContactMethodsColumns.DATA));
String imType
= imCur.getString(imCur.getColumnIndex(Contacts.ContactMethodsColumns.TYPE));
if (imName.length() > 0) {
IM im
= new IM(imName, imType);
imList.add(im);
}
}
imCur.close();
return(imList);
}

public Organization getContactOrg(String id) {
Organization org
= new Organization();
String where
= Contacts.ContactMethods.PERSON_ID + " = ?";
String[] whereParameters
= new String[]{id};

Cursor orgCur
= this.cr.query(Contacts.Organizations.CONTENT_URI, null, where, whereParameters, null);

if (orgCur.moveToFirst()) {
String orgName
= orgCur.getString(orgCur.getColumnIndex(Contacts.Organizations.COMPANY));
String title
= orgCur.getString(orgCur.getColumnIndex(Contacts.Organizations.TITLE));
if (orgName.length() > 0) {
org.setOrganization(orgName);
org.setTitle(title);
}
}
orgCur.close();
return(org);
}
}
复制代码

这篇关于Android Contacts的使用(三)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/255133

相关文章

Java Lambda表达式的使用详解

《JavaLambda表达式的使用详解》:本文主要介绍JavaLambda表达式的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、前言二、Lambda表达式概述1. 什么是Lambda表达式?三、Lambda表达式的语法规则1. 无参数的Lambda表

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

详解如何使用Python构建从数据到文档的自动化工作流

《详解如何使用Python构建从数据到文档的自动化工作流》这篇文章将通过真实工作场景拆解,为大家展示如何用Python构建自动化工作流,让工具代替人力完成这些数字苦力活,感兴趣的小伙伴可以跟随小编一起... 目录一、Excel处理:从数据搬运工到智能分析师二、PDF处理:文档工厂的智能生产线三、邮件自动化:

Spring @RequestMapping 注解及使用技巧详解

《Spring@RequestMapping注解及使用技巧详解》@RequestMapping是SpringMVC中定义请求映射规则的核心注解,用于将HTTP请求映射到Controller处理方法... 目录一、核心作用二、关键参数说明三、快捷组合注解四、动态路径参数(@PathVariable)五、匹配请

Java 枚举的基本使用方法及实际使用场景

《Java枚举的基本使用方法及实际使用场景》枚举是Java中一种特殊的类,用于定义一组固定的常量,枚举类型提供了更好的类型安全性和可读性,适用于需要定义一组有限且固定的值的场景,本文给大家介绍Jav... 目录一、什么是枚举?二、枚举的基本使用方法定义枚举三、实际使用场景代替常量状态机四、更多用法1.实现接

springboot项目中使用JOSN解析库的方法

《springboot项目中使用JOSN解析库的方法》JSON,全程是JavaScriptObjectNotation,是一种轻量级的数据交换格式,本文给大家介绍springboot项目中使用JOSN... 目录一、jsON解析简介二、Spring Boot项目中使用JSON解析1、pom.XML文件引入依

Java中的record使用详解

《Java中的record使用详解》record是Java14引入的一种新语法(在Java16中成为正式功能),用于定义不可变的数据类,这篇文章给大家介绍Java中的record相关知识,感兴趣的朋友... 目录1. 什么是 record?2. 基本语法3. record 的核心特性4. 使用场景5. 自定

Python使用Tkinter打造一个完整的桌面应用

《Python使用Tkinter打造一个完整的桌面应用》在Python生态中,Tkinter就像一把瑞士军刀,它没有花哨的特效,却能快速搭建出实用的图形界面,作为Python自带的标准库,无需安装即可... 目录一、界面搭建:像搭积木一样组合控件二、菜单系统:给应用装上“控制中枢”三、事件驱动:让界面“活”

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

C/C++ chrono简单使用场景示例详解

《C/C++chrono简单使用场景示例详解》:本文主要介绍C/C++chrono简单使用场景示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友... 目录chrono使用场景举例1 输出格式化字符串chrono使用场景China编程举例1 输出格式化字符串示