在mysql url后面加了时区参数修正了读取数据时区错误的问题
parent
9aabe748d6
commit
5c8eb21401
|
|
@ -1,5 +1,5 @@
|
||||||
import com.alibaba.druid.pool.DruidDataSource
|
|
||||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
|
||||||
|
import com.jfinal.plugin.druid.DruidPlugin
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import ro.pippo.controller.ControllerApplication
|
import ro.pippo.controller.ControllerApplication
|
||||||
import ro.pippo.core.Pippo
|
import ro.pippo.core.Pippo
|
||||||
|
|
@ -13,6 +13,7 @@ import route.*
|
||||||
object Main {
|
object Main {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
// System.setProperty("user.timezone","Asia/Shanghai");
|
||||||
val pippo = Pippo(BasicApplication())
|
val pippo = Pippo(BasicApplication())
|
||||||
pippo.start()
|
pippo.start()
|
||||||
}
|
}
|
||||||
|
|
@ -55,8 +56,13 @@ class BasicApplication : ControllerApplication() {
|
||||||
addControllers(CtrlRole::class.java)
|
addControllers(CtrlRole::class.java)
|
||||||
|
|
||||||
|
|
||||||
// val activeRecord = ActiveRecordPlugin(druidDataSource)
|
val dp = DruidPlugin(
|
||||||
// activeRecord.start()
|
"jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram?serverTimezone=Asia/Shanghai",
|
||||||
|
"shzhyjxy",
|
||||||
|
"Admin111")
|
||||||
|
val arp = ActiveRecordPlugin(dp)
|
||||||
|
dp.start()
|
||||||
|
arp.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createRequestResponseFactory(): RequestResponseFactory {
|
override fun createRequestResponseFactory(): RequestResponseFactory {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
import config.Const
|
import config.Const
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelGroup
|
import model.ModelGroup
|
||||||
|
|
@ -34,9 +35,9 @@ class CrtlGroup : Controller() {
|
||||||
|
|
||||||
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :JSONResponse {
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
val list = service.pagiGroup(num,size)
|
val page = service.pagiGroup(num,size)
|
||||||
return responseSuccess(list)
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET("/{id: [0-9]+}")
|
@GET("/{id: [0-9]+}")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelMenu
|
import model.ModelMenu
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
|
|
@ -27,9 +28,9 @@ class CtrlMenu : Controller() {
|
||||||
|
|
||||||
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :JSONResponse {
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
val list = service.pagiMenu(num,size)
|
val page = service.pagiMenu(num,size)
|
||||||
return responseSuccess(list)
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET("/byRole/{roleId: [0-9]+}")
|
@GET("/byRole/{roleId: [0-9]+}")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelPerm
|
import model.ModelPerm
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
|
|
@ -27,9 +28,9 @@ class CtrlPerm : Controller() {
|
||||||
|
|
||||||
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :JSONResponse {
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
val list = service.pagiPerm(num,size)
|
val page = service.pagiPerm(num,size)
|
||||||
return responseSuccess(list)
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST("/byRole/{roleId: [0-9]+}")
|
@POST("/byRole/{roleId: [0-9]+}")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelRole
|
import model.ModelRole
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
|
|
@ -27,9 +28,9 @@ class CtrlRole : Controller() {
|
||||||
|
|
||||||
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :JSONResponse {
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
val list = service.pagiRole(num,size)
|
val page = service.pagiRole(num,size)
|
||||||
return responseSuccess(list)
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET("/byUser/{userId: [0-9]+}")
|
@GET("/byUser/{userId: [0-9]+}")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelUser
|
import model.ModelUser
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
|
|
@ -30,9 +31,9 @@ class CtrlUser : Controller() {
|
||||||
|
|
||||||
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :JSONResponse {
|
fun pagi(@Param("page") num: Int, @Param("size") size: Int): String {
|
||||||
val list = service.pagiUser(num,size)
|
val page = service.pagiUser(num, size)
|
||||||
return responseSuccess(list)
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST("/")
|
@POST("/")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Page
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import model.*
|
import model.*
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||||
import util.*
|
import util.*
|
||||||
|
|
@ -408,78 +411,23 @@ class Service {
|
||||||
.execute("update `menu` set permId=-1 where id=$menuId")
|
.execute("update `menu` set permId=-1 where id=$menuId")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pagiUser(page: Int, size: Int): MutableList<ModelUser> {
|
fun pagiUser(page: Int, size: Int): Page<Record> {
|
||||||
val conn = DBUtil.getConnection()
|
return Db.paginate(page, size, "select *", "from `user`")
|
||||||
try {
|
|
||||||
val rs = conn.createStatement()
|
|
||||||
.executeQuery("select * from `user` limit $size offset ${(page - 1) * size}")
|
|
||||||
val list = mutableListOf<ModelUser>()
|
|
||||||
while (rs.next()) {
|
|
||||||
list.add(rsToUser(rs))
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
} finally {
|
|
||||||
conn.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pagiGroup(page: Int, size: Int): MutableList<ModelGroup> {
|
fun pagiGroup(page: Int, size: Int): Page<Record> {
|
||||||
val conn = DBUtil.getConnection()
|
return Db.paginate(page, size, "select *", "from `group`")
|
||||||
try {
|
|
||||||
val rs = conn.createStatement()
|
|
||||||
.executeQuery("select * from `group` limit $size offset ${(page - 1) * size}")
|
|
||||||
val list = mutableListOf<ModelGroup>()
|
|
||||||
while (rs.next()) {
|
|
||||||
list.add(rsToGroup(rs))
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
} finally {
|
|
||||||
conn.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pagiMenu(page: Int, size: Int): MutableList<ModelMenu> {
|
fun pagiMenu(page: Int, size: Int): Page<Record> {
|
||||||
val conn = DBUtil.getConnection()
|
return Db.paginate(page, size, "select *", "from `menu`")
|
||||||
try {
|
|
||||||
val rs = conn.createStatement()
|
|
||||||
.executeQuery("select * from `menu` limit $size offset ${(page - 1) * size}")
|
|
||||||
val list = mutableListOf<ModelMenu>()
|
|
||||||
while (rs.next()) {
|
|
||||||
list.add(rsToMenu(rs))
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
} finally {
|
|
||||||
conn.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pagiPerm(page: Int, size: Int): MutableList<ModelPerm> {
|
fun pagiPerm(page: Int, size: Int): Page<Record> {
|
||||||
val conn = DBUtil.getConnection()
|
return Db.paginate(page, size, "select *", "from `perm`")
|
||||||
try {
|
|
||||||
val rs = conn.createStatement()
|
|
||||||
.executeQuery("select * from `perm` limit $size offset ${(page - 1) * size}")
|
|
||||||
val list = mutableListOf<ModelPerm>()
|
|
||||||
while (rs.next()) {
|
|
||||||
list.add(rsToPerm(rs))
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
} finally {
|
|
||||||
conn.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pagiRole(page: Int, size: Int): MutableList<ModelRole> {
|
fun pagiRole(page: Int, size: Int): Page<Record> {
|
||||||
val conn = DBUtil.getConnection()
|
return Db.paginate(page, size, "select *", "from `role`")
|
||||||
try {
|
|
||||||
val rs = conn.createStatement()
|
|
||||||
.executeQuery("select * from `role` limit $size offset ${(page - 1) * size}")
|
|
||||||
val list = mutableListOf<ModelRole>()
|
|
||||||
while (rs.next()) {
|
|
||||||
list.add(rsToRole(rs))
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
} finally {
|
|
||||||
conn.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ object DBUtil {
|
||||||
private val druidDataSource: DruidDataSource = DruidDataSource()
|
private val druidDataSource: DruidDataSource = DruidDataSource()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
druidDataSource.url = "jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram"
|
druidDataSource.url = "jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram?serverTimezone=GMT"
|
||||||
druidDataSource.driverClassName = "com.mysql.cj.jdbc.Driver"
|
druidDataSource.driverClassName = "com.mysql.cj.jdbc.Driver"
|
||||||
druidDataSource.username = "shzhyjxy"
|
druidDataSource.username = "shzhyjxy"
|
||||||
druidDataSource.password = "Admin111"
|
druidDataSource.password = "Admin111"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,11 @@ import config.Const
|
||||||
import model.*
|
import model.*
|
||||||
import java.sql.ResultSet
|
import java.sql.ResultSet
|
||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.time.Clock
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import java.time.ZoneId
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun responseNotFoundById(): JSONResponse {
|
fun responseNotFoundById(): JSONResponse {
|
||||||
return JSONResponse(Const.codeResourceNotFound, Const.msgNotFoundById, null)
|
return JSONResponse(Const.codeResourceNotFound, Const.msgNotFoundById, null)
|
||||||
|
|
@ -66,7 +70,7 @@ fun rsToRole(rs: ResultSet): ModelRole {
|
||||||
fun roleToInsertSQL(role: ModelRole): String {
|
fun roleToInsertSQL(role: ModelRole): String {
|
||||||
return """
|
return """
|
||||||
insert into `role`(description,createTime)
|
insert into `role`(description,createTime)
|
||||||
values('${role.description}','${Timestamp.from(Instant.now())}')
|
values('${role.description}','${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}')
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue