1.di proyek build.gradle
tambahkan
2.di app build.gradle
tambahkan
dependencies {
...
compile 'ljk.android.pangjiao:pangjiao:1.0.2'
annotationProcessor 'ljk.android.pangjiao:pangjiao:1.0.2'
}
android {
compileOptions {
...
sourceCompatibility JavaVersion . VERSION_1_8
targetCompatibility JavaVersion . VERSION_1_8
}
}
###inisialisasi ###
public class TESTApplication extends Application {
@ Override
public void onCreate () {
super . onCreate ();
PangJiao . init ( this );
}
}
1. digunakan dalam aktivitas
public class MainActivity extends PJAppCompatActivity {
@ InitView ( R . id . tv_title )
public TextView tvTitle ;
@ Override
public int initView () {
return R . layout . activity_main ;
}
@ Override
public void initData () {
tvTitle . setText ( "hello " );
}
@ OnClick ( R . id . tv_title )
public void tvClick () {
Toast . makeText ( this , tvTitle . getText (). toString (), Toast . LENGTH_SHORT ). show ();
}
@ OnClick ( R . id . tv_title )
public View . OnClickListener tvTitle_Click = v -> {
Toast . makeText ( this , tvTitle . getText (). toString (), Toast . LENGTH_SHORT ). show ();
};
@ OnClick ({ R . id . tv_title , R . id . tv_text })
public void onClick ( View view ){
}
Atau
PangJiao . inject ( activity );
2.gunakan dalam fragmen
public class TESTFragment extends PJFragment {
@ InitView ( R . id . btn_test )
public Button btnTest ;
@ Override
protected int initView () {
return R . layout . fragment_test ;
}
@ Override
protected void initData () {
btnTest . setText ( "hello pangjiao" );
}
}
Atau
PangJiao . inject ( view , object );
dalam kerangka pangjiao hava @Service @Presenter anotasi,Orang yang mengetahui tentang pegas mengetahui @Autowire.at pangjiao hava @Autowire dan @AutowireProxy . pangjiao menyarankan Anda mensubkontrakkan kode Anda ke direktori berikut.
ui (paket) -aktivitas (paket) -fragmen (paket)
layanan -antarmuka(.java) -imp (paket)
aplikasi -antarmuka(.java) -imp (paket)
Mulailah menggunakan pangjia
antarmuka tingkat aplikasi antarmuka baru
public interface IMemberPresent extends IPresenter {
void login ( String name , String pwd );
}
tambahkan imp
@ Presenter
public class MemberPresent implements IMemberPresent {
@ Autowire
public IAppService appService ;
@ TargetView
public IMemberView memberView ;
@ Override
public void onDestroy () {
this . memberView = null ;
}
@ Override
public void login ( String name , String pwd ) {
appService . login ( name , pwd );
}
}
tingkat ui
public class MainActivity extends PJAppCompatActivity implements IMemberView {
@ AutowireProxy
public IMemberPresent memberPresent ;
@ Override
public int initView () {
return R . layout . activity_main ;
}
@ Override
public void initData () {
memberPresent . login ( "Tom" , "123456" );
}
@ Override
public void refresh ( Object o ) {
}
}
Pelanggaran POST default, Format badan permintaan JSON. Lapisan yang mendasarinya adalah implementasi HttpURLConnection.
@ Net ( api = "http://www.baidu.com" , connectTimeOut = 10000 )
public class RequestActive extends NetModel < ResponseActive > {
private String ActiveCode ;
public String getActiveCode () {
return ActiveCode ;
}
public void setActiveCode ( String ActiveCode ) {
this . ActiveCode = ActiveCode ;
}
}
public class ResponseActive extends ResponseBase {
private boolean issuccess ;
private String msg ;
private String data ;
public boolean isIssuccess () {
return issuccess ;
}
public void setIssuccess ( boolean issuccess ) {
this . issuccess = issuccess ;
}
public String getMsg () {
return msg ;
}
public void setMsg ( String msg ) {
this . msg = msg ;
}
public String getData () {
return data ;
}
public void setData ( String data ) {
this . data = data ;
}
}
bagaimana penggunaannya? xx.excute();//sinkronisasi thread
public ResponseActive active ( String activeCode ) {
RequestActive requestActive = new RequestActive ();
requestActive . setActiveCode ( activeCode );
return requestActive . execute ();
}
Entitas dan @Entitas, Atribut publik, Tidak ada kelas enkapsulasi
@ Entity
public class User {
@ Id
public int id ;
@ Column
public String userName ;
@ Column
public String telPhone ;
}
tambahkan, perbarui data, kueri, hapus
@ Override
public void queryUser ( String userName ) {
//添加新的:user,更新同样的方法,确保Id不为0
User user = new User ();
user . userName = userName ;
user . telPhone = "1322222222" ;
SQEntity . save ( user );
//查询:构建实体
User userQuery = new User ();
userQuery . userName = userName ;
List < User > search = SQEntity . search ( User . class , userQuery );
//查询:where
List < User > search1 = SQEntity . search ( User . class , "userName = '" + userName + " '" );
//删除:构建实体
User userDelete = new User ();
userDelete . telPhone = "1322222222" ;
SQEntity . deleteWhere ( User . class , userDelete );
//删除:Id
SQEntity . delete ( User . class , 2 );
}
Saat ini, bukan hanya kueri asosiatif yang didukung.
Gunakan @Autowireproxy saat memasukkan objek ke dalam lapisan UI.
@autowireproxy akan menyuntikkan objek proxy yang akan dieksekusi di thread .
Jadi permintaan jaringan di lapisan Aplikasi tingkat UI tidak perlu memulai thread itu sendiri.
Objek yang perlu dikelola oleh container pangjiao perlu ditambahkan ke @service atau @Presenter . Kelas yang dihiasi oleh * @service atau *** @presenter**, tidak mempunyai variabel anggota lain.