创建数据库实体类:Province、City、County;使用litepal操作数据库,目前项目有关litepal的部分都爆红,原因应该包还未引进;

flameking 4 years ago
parent e6fbfa96ab
commit 04d6bc022d

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/Android/FlamekingWeather/app/src/main/res/layout/layout.xml" value="0.2390625" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>

@ -28,7 +28,16 @@ android {
}
dependencies {
implementation fileTree(dir: 'libs', includes: ['*.jar'])
testImplementation 'junit:junit:4.12'
// litepalJPA
implementation 'org.litepal.guolindev:core:3.2.3'
// okhttp
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
// gsonjson
implementation 'com.google.code.gson:gson:2.7'
// glide
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

@ -3,6 +3,7 @@
package="com.casflawed.flameking.weather">
<application
android:name="org.litepal.LitePalApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<litepal>
<dbname value="flameking_weather"/>
<version value="1"/>
<list>
<mapping class="com.casflawed.flameking.weather.db.Province"/>
<mapping class="com.casflawed.flameking.weather.db.City"/>
<mapping class="com.casflawed.flameking.weather.db.County"/>
</list>
</litepal>

@ -0,0 +1,50 @@
package com.casflawed.flameking.weather.db;
public class City extends LitePalSupport{
private Integer id;
private String cityName;
private Integer cityCode;
private Integer provinceId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public Integer getCityCode() {
return cityCode;
}
public void setCityCode(Integer cityCode) {
this.cityCode = cityCode;
}
public Integer getProvinceId() {
return provinceId;
}
public void setProvinceId(Integer provinceId) {
this.provinceId = provinceId;
}
@Override
public String toString() {
return "City{" +
"id=" + id +
", cityName='" + cityName + '\'' +
", cityCode=" + cityCode +
", provinceId=" + provinceId +
'}';
}
}

@ -0,0 +1,50 @@
package com.casflawed.flameking.weather.db;
public class County extends LitePalSupport{
private Integer id;
private String countyName;
private Integer weatherId;
private Integer cityId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCountyName() {
return countyName;
}
public void setCountyName(String countyName) {
this.countyName = countyName;
}
public Integer getWeatherId() {
return weatherId;
}
public void setWeatherId(Integer weatherId) {
this.weatherId = weatherId;
}
public Integer getCityId() {
return cityId;
}
public void setCityId(Integer cityId) {
this.cityId = cityId;
}
@Override
public String toString() {
return "County{" +
"id=" + id +
", countyName='" + countyName + '\'' +
", weatherId=" + weatherId +
", cityId=" + cityId +
'}';
}
}

@ -0,0 +1,40 @@
package com.casflawed.flameking.weather.db;
public class Province extends LitePalSupport{
private Integer id;
private Integer provinceCode;
private String provinceName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProvinceCode() {
return provinceCode;
}
public void setProvinceCode(Integer provinceCode) {
this.provinceCode = provinceCode;
}
public String getProvinceName() {
return provinceName;
}
public void setProvinceName(String provinceName) {
this.provinceName = provinceName;
}
@Override
public String toString() {
return "Province{" +
"id=" + id +
", provinceCode=" + provinceCode +
", provinceName='" + provinceName + '\'' +
'}';
}
}

@ -18,4 +18,5 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.enableJetifier=true
Loading…
Cancel
Save