Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_street
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_street
Commits
79a9f635
Commit
79a9f635
authored
Jul 20, 2021
by
fengruiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建项目的room数据已完成
创建景区的表结构已完成
parent
1ea0bdb7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
0 deletions
+82
-0
build.gradle
app/build.gradle
+8
-0
AppDatabase.kt
app/src/main/java/db/AppDatabase.kt
+35
-0
ScenicSpotDao.kt
app/src/main/java/db/ScenicSpotDao.kt
+14
-0
TableBean.kt
app/src/main/java/db/TableBean.kt
+25
-0
No files found.
app/build.gradle
View file @
79a9f635
...
@@ -188,5 +188,13 @@ dependencies {
...
@@ -188,5 +188,13 @@ dependencies {
implementation
(
name:
'BaiduLBS_AndroidSDK_Lib'
,
ext:
'aar'
)
implementation
(
name:
'BaiduLBS_AndroidSDK_Lib'
,
ext:
'aar'
)
//room数据库
def
room_version
=
"2.3.0"
implementation
(
"androidx.room:room-runtime:$room_version"
)
annotationProcessor
"androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
implementation
(
"androidx.room:room-ktx:$room_version"
)
// optional - Test helpers
testImplementation
(
"androidx.room:room-testing:$room_version"
)
}
}
\ No newline at end of file
app/src/main/java/db/AppDatabase.kt
0 → 100644
View file @
79a9f635
package
db
import
androidx.room.Database
import
androidx.room.Room
import
androidx.room.RoomDatabase
import
me.goldze.mvvmhabit.utils.Utils
/**
* Created by 冯瑞雨 on 2021/7/20.
*/
@Database
(
entities
=
[
ScenicSpotBean
::
class
],
version
=
1
)
abstract
class
AppDatabase
:
RoomDatabase
()
{
abstract
fun
userDao
():
ScenicSpotDao
companion
object
{
private
var
_instance
:
AppDatabase
?
=
null
@JvmStatic
fun
instance
():
AppDatabase
{
if
(
_instance
==
null
)
{
synchronized
(
AppDatabase
::
class
.
java
)
{
if
(
_instance
==
null
)
{
_instance
=
Room
.
databaseBuilder
(
Utils
.
getContext
()
,
AppDatabase
::
class
.
java
,
"mints_room.db"
)
.
allowMainThreadQueries
()
//设置是否允许在主线程做查询操作
//.fallbackToDestructiveMigration()//设置迁移数据库如果发生错误,将会重新创建数据库,而不是发生崩溃
.
build
()
}
}
}
return
_instance
!!
}
}
}
\ No newline at end of file
app/src/main/java/db/ScenicSpotDao.kt
0 → 100644
View file @
79a9f635
package
db
import
androidx.room.Dao
import
androidx.room.Query
import
java.util.*
/**
* Created by 冯瑞雨 on 2021/7/20.
*/
@Dao
interface
ScenicSpotDao
{
@Query
(
"SELECT * FROM scenic_spot"
)
fun
getAll
():
List
<
ScenicSpotBean
>
}
\ No newline at end of file
app/src/main/java/db/TableBean.kt
0 → 100644
View file @
79a9f635
package
db
import
androidx.room.Entity
import
androidx.room.PrimaryKey
import
java.util.*
/**
* Created by 冯瑞雨 on 2021/7/20.
* 景区表
*/
@Entity
(
tableName
=
"scenic_spot"
)
class
ScenicSpotBean
(
//主键 自增
@PrimaryKey
(
autoGenerate
=
true
)
var
id
:
Int
=
0
,
//景区 类型 1=境内热门景区 2=境内免费专区 3=首页的景区
var
type
:
Int
=
0
,
//景区 经度
var
longitude
:
Double
?=
null
,
//景区 纬度
var
latitude
:
Double
?=
null
,
//景区 名称
var
name
:
String
?
=
null
,
//景区 图片
var
images
:
List
<
String
>?
=
null
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment