简单来说:JDBC是一种开放标准的跨编程语言、跨数据库类型编程API。各类型数据库产品厂商都会按它的标准要求来提供针对自身产品的JDBC驱动程序。最主要的这是一套成熟的工具,在编程人员中使用很普及。既然我们的目标是开发一套标准的大数据系统集成API,那么采用JDBC系统数据接口可以沿用业内丰富的技术资源、覆盖更多类型用户的编程需要,以及降低使用门槛。对于scala编程语言来讲,ScalikeJDBC是一套最合适满足我们下面开发要求的工具库,因为它可以用最简单易用的方式来实现JDBC的基本功能。

JDBC的基本组件和工作原理比较简单:核心组件就connection、statement(preparedstatement)两个对象。connection提供与数据库的连接以及数据处理的运行环境,statement是connection的一个属性,包含了可运行的SQL语句及对它们的各种运算方法。下面我们就用ScalikeJDBC官网上的例子来示范说明ScalikeJDBC的应用:

  1. import scalikejdbc._
  2. object JDBCIntro extends App {
  3. //standard java procedure to register driver
  4. Class.forName("org.h2.Driver")
  5. //default connectionPool named 'default
  6. //ConnectionPool.singleton("jdbc:h2:mem:hello", "user", "pass")
  7. //or ConnectionPool.add('default,"jdbc:h2:mem:hello", "user", "pass")
  8. //db name is 'h2mem
  9. ConnectionPool.add('h2mem,"jdbc:h2:mem:hello", "user", "pass")

首先,登记jdbc驱动程序及准备连接池connection-pool。注意,ScalikeJDBC提供了固定名为'default的默认连接池。所以ConnectionPool.singleton == ConnectionPool.add('default。在'default连接池上的操作都无需提供名称,如:(DB==NamedDB('default)),(AutoSession==NamedAutoSession('default))等。上面的代码示范了手工方式的连接池设置。如果应用需要替换增加数据库或调整数据库参数必须通过修改代码来实现。实用的程序应该使用配置文件的方式进行数据库设置可以轻松随意调整数据库参数,我们会在下一章介绍配置文件使用方法。

跟着是一条SQL语句的构建和运算:

  1. //construct SQL object
  2. val createSQL: SQL[Nothing,NoExtractor] =SQL("""
  3. create table members (
  4. id bigint primary key auto_increment,
  5. name varchar() not null,
  6. description varchar(),
  7. birthday date,
  8. created_at timestamp not null
  9. )""")
  10.  
  11. //implicit val session = AutoSession 'default
  12. //run this SQL
  13. createSQL.execute().apply()(NamedAutoSession('h2mem)) //autoCommit

通过SQL("...")方法构建SQL[A,E]类型的实例,用execute()方法设定不同的运算方式,然后用apply()(implicit s:DBSession)来实际运算SQL,DBSession其实就是个connection实例。相关SQL[A,E]的类型定义如下:

  1. /**
  2. * SQL abstraction.
  3. *
  4. * @param statement SQL template
  5. * @param rawParameters parameters
  6. * @param f extractor function
  7. * @tparam A return type
  8. */
  9. abstract class SQL[A, E <: WithExtractor](
  10. val statement: String,
  11. private[scalikejdbc] val rawParameters: Seq[Any]
  12. )(f: WrappedResultSet => A)
  13. extends Extractor[A] {...}
  14.  
  15. /**
  16. * Extractor
  17. */
  18. private[scalikejdbc] trait Extractor[A] {
  19. def extractor: (WrappedResultSet) => A
  20. }

SQL("...")调用了apply构建方法:

  1. object SQL {
  2. ...
  3. def apply[A](sql: String): SQL[A, NoExtractor] = new SQLToTraversableImpl[A, NoExtractor](sql, Seq.empty)(noExtractor[A](
  4. ErrorMessage.THIS_IS_A_BUG
  5. ))
  6. }
  7.  
  8. /**
  9. * SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.Traversable value.
  10. *
  11. * @param statement SQL template
  12. * @param rawParameters parameters
  13. * @param extractor extractor function
  14. * @tparam A return type
  15. */
  16. class SQLToTraversableImpl[A, E <: WithExtractor](
  17. override val statement: String, override val rawParameters: Seq[Any]
  18. )(
  19. override val extractor: WrappedResultSet => A
  20. )
  21. extends SQL[A, E](statement, rawParameters)(extractor)
  22. with SQLToTraversable[A, E] {
  23.  
  24. override protected def withParameters(params: Seq[Any]): SQLToResult[A, E, Traversable] = {
  25. new SQLToTraversableImpl[A, E](statement, params)(extractor)
  26. }
  27.  
  28. override protected def withStatementAndParameters(state: String, params: Seq[Any]): SQLToResult[A, E, Traversable] = {
  29. new SQLToTraversableImpl[A, E](state, params)(extractor)
  30. }
  31.  
  32. override protected def withExtractor[B](f: WrappedResultSet => B): SQLToResult[B, HasExtractor, Traversable] = {
  33. new SQLToTraversableImpl[B, HasExtractor](statement, rawParameters)(f)
  34. }
  35.  
  36. }

SQLToTraversableImpl类型提供了SQL语句参数组合方法并构建SQLToResult类型:

  1. trait SQLToResult[A, E <: WithExtractor, C[_]] extends SQL[A, E] with Extractor[A] {
  2. import GeneralizedTypeConstraintsForWithExtractor._
  3.  
  4. def result[AA](f: WrappedResultSet => AA, session: DBSession): C[AA]
  5. val statement: String
  6. private[scalikejdbc] val rawParameters: Seq[Any]
  7. def apply()(
  8. implicit
  9. session: DBSession,
  10. context: ConnectionPoolContext = NoConnectionPoolContext,
  11. hasExtractor: ThisSQL =:= SQLWithExtractor
  12. ): C[A] = {
  13. val attributesSwitcher = createDBSessionAttributesSwitcher()
  14. val f: DBSession => C[A] = s => result[A](extractor, DBSessionWrapper(s, attributesSwitcher))
  15. // format: OFF
  16. session match {
  17. case AutoSession | ReadOnlyAutoSession => DB.readOnly(f)
  18. case NamedAutoSession(name, _) => NamedDB(name, session.settings).readOnly(f)
  19. case ReadOnlyNamedAutoSession(name, _) => NamedDB(name, session.settings).readOnly(f)
  20. case _ => f(session)
  21. }
  22. // format: ON
  23. }
  24. }

这个SQLToResult的apply方法就是SQL-readonly-query的运算方法。

SQL[A,E]中类型参数A是运算SQL返回值类型,E是一种函数类型:(WrappedResultSet => A),用来把返回结果转换成A类型值。SQL类型还提供了bind,bindByName方法来绑定SQL参数。SQL是个泛式的类型,除默认转换成Query型的SQLToResult类型外还可以转换成execute、update、batch等等其它SQL类型:

  1. /**
  2. * Binds parameters for batch
  3. *
  4. * @param parameters parameters
  5. * @return SQL for batch
  6. */
  7. def batch(parameters: Seq[Any]*): SQLBatch = {
  8. new SQLBatch(statement, parameters, tags)
  9. }
  10. /**
  11. * Binds parameters for largeBatch
  12. *
  13. * @param parameters parameters
  14. * @return SQL for batch
  15. */
  16. def largeBatch(parameters: Seq[Any]*): SQLLargeBatch =
  17. new SQLLargeBatch(statement, parameters, tags)
  18. /**
  19. * Binds parameters for batch
  20. *
  21. * @param parameters parameters
  22. * @return SQL for batch
  23. */
  24. def batchAndReturnGeneratedKey(parameters: Seq[Any]*): SQLBatchWithGeneratedKey = {
  25. new SQLBatchWithGeneratedKey(statement, parameters, tags)(None)
  26. }
  27. /**
  28. * Binds parameters for batch
  29. *
  30. * @param generatedKeyName generated key name
  31. * @param parameters parameters
  32. * @return SQL for batch
  33. */
  34. def batchAndReturnGeneratedKey(generatedKeyName: String, parameters: Seq[Any]*): SQLBatchWithGeneratedKey = {
  35. new SQLBatchWithGeneratedKey(statement, parameters, tags)(Some(generatedKeyName))
  36. }
  37. /**
  38. * Binds parameters for batch
  39. *
  40. * @param parameters parameters
  41. * @return SQL for batch
  42. */
  43. def batchByName(parameters: Seq[(Symbol, Any)]*): SQLBatch = {
  44. val names = SQLTemplateParser.extractAllParameters(statement)
  45. val sqlWithPlaceHolders = SQLTemplateParser.convertToSQLWithPlaceHolders(statement)
  46. val _sql = validateAndConvertToNormalStatement(statement, sqlWithPlaceHolders, names, _settings, parameters.headOption.getOrElse(Seq.empty))._1
  47. val _parameters: Seq[Seq[Any]] = parameters.map { p =>
  48. validateAndConvertToNormalStatement(statement, sqlWithPlaceHolders, names, _settings, p)._2
  49. }
  50. new SQLBatch(_sql, _parameters, tags)
  51. }
  52. /**
  53. * Set execution type as execute
  54. *
  55. * @return SQL instance
  56. */
  57. def execute(): SQLExecution = {
  58. new SQLExecution(statement, rawParameters, tags)((stmt: PreparedStatement) => {})((stmt: PreparedStatement) => {})
  59. }
  60. /**
  61. * Set execution type as execute with filters
  62. *
  63. * @param before before filter
  64. * @param after after filter
  65. * @return SQL instance
  66. */
  67. def executeWithFilters(before: (PreparedStatement) => Unit, after: (PreparedStatement) => Unit): SQLExecution = {
  68. new SQLExecution(statement, rawParameters, tags)(before)(after)
  69. }
  70. /**
  71. * Set execution type as executeUpdate
  72. *
  73. * @return SQL instance
  74. */
  75. def executeUpdate(): SQLUpdate = update()
  76. /**
  77. * Set execution type as executeUpdate with filters
  78. *
  79. * @param before before filter
  80. * @param after after filter
  81. * @return SQL instance
  82. */
  83. def executeUpdateWithFilters(before: (PreparedStatement) => Unit, after: (PreparedStatement) => Unit): SQLUpdate = {
  84. updateWithFilters(before, after)
  85. }
  86. /**
  87. * Set execution type as executeUpdate
  88. *
  89. * @return SQL instance
  90. */
  91. def update(): SQLUpdate = {
  92. new SQLUpdate(statement, rawParameters, tags)((stmt: PreparedStatement) => {})((stmt: PreparedStatement) => {})
  93. }
  94. /**
  95. * Set execution type as executeUpdate with filters
  96. *
  97. * @param before before filter
  98. * @param after after filter
  99. * @return SQL instance
  100. */
  101. def updateWithFilters(before: (PreparedStatement) => Unit, after: (PreparedStatement) => Unit): SQLUpdate = {
  102. new SQLUpdate(statement, rawParameters, tags)(before)(after)
  103. }
  104. /**
  105. * Set execution type as `executeLargeUpdate`
  106. *
  107. * @return SQL instance
  108. */
  109. def largeUpdate(): SQLLargeUpdate =
  110. new SQLLargeUpdate(statement, rawParameters, tags)(_ => {})(_ => {})
  111. /**
  112. * Set execution type as `executeLargeUpdate` with filters
  113. *
  114. * @param before before filter
  115. * @param after after filter
  116. * @return SQL instance
  117. */
  118. def largeUpdateWithFilters(before: PreparedStatement => Unit, after: PreparedStatement => Unit): SQLLargeUpdate =
  119. new SQLLargeUpdate(statement, rawParameters, tags)(before)(after)
  120. /**
  121. * Set execution type as updateAndReturnGeneratedKey
  122. *
  123. * @return SQL instance
  124. */
  125. def updateAndReturnGeneratedKey(): SQLUpdateWithGeneratedKey = {
  126. updateAndReturnGeneratedKey()
  127. }
  128. def updateAndReturnGeneratedKey(name: String): SQLUpdateWithGeneratedKey = {
  129. new SQLUpdateWithGeneratedKey(statement, rawParameters, this.tags)(name)
  130. }
  131. def updateAndReturnGeneratedKey(index: Int): SQLUpdateWithGeneratedKey = {
  132. new SQLUpdateWithGeneratedKey(statement, rawParameters, this.tags)(index)
  133. }

以上每种SQL类型都是一种特别的SQL运算方式,即它们都有自己独特的apply()函数如:

  1. /**
  2. * SQL which execute java.sql.Statement#execute().
  3. *
  4. * @param statement SQL template
  5. * @param parameters parameters
  6. * @param before before filter
  7. * @param after after filter
  8. */
  9. class SQLExecution(val statement: String, val parameters: Seq[Any], val tags: Seq[String] = Nil)(
  10. val before: (PreparedStatement) => Unit
  11. )(
  12. val after: (PreparedStatement) => Unit
  13. ) {
  14.  
  15. def apply()(implicit session: DBSession): Boolean = {
  16. val attributesSwitcher = new DBSessionAttributesSwitcher(SQL("").tags(tags: _*))
  17. val f: DBSession => Boolean = DBSessionWrapper(_, attributesSwitcher).executeWithFilters(before, after, statement, parameters: _*)
  18. // format: OFF
  19. session match {
  20. case AutoSession => DB.autoCommit(f)
  21. case NamedAutoSession(name, _) => NamedDB(name, session.settings).autoCommit(f)
  22. case ReadOnlyAutoSession => DB.readOnly(f)
  23. case ReadOnlyNamedAutoSession(name, _) => NamedDB(name, session.settings).readOnly(f)
  24. case _ => f(session)
  25. }
  26. // format: ON
  27. }
  28.  
  29. }
  30.  
  31. /**
  32. * SQL which execute java.sql.Statement#executeUpdate().
  33. *
  34. * @param statement SQL template
  35. * @param parameters parameters
  36. * @param before before filter
  37. * @param after after filter
  38. */
  39. class SQLUpdate(val statement: String, val parameters: Seq[Any], val tags: Seq[String] = Nil)(
  40. val before: (PreparedStatement) => Unit
  41. )(
  42. val after: (PreparedStatement) => Unit
  43. ) {
  44.  
  45. def apply()(implicit session: DBSession): Int = {
  46. val attributesSwitcher = new DBSessionAttributesSwitcher(SQL("").tags(tags: _*))
  47. session match {
  48. case AutoSession =>
  49. DB.autoCommit(DBSessionWrapper(_, attributesSwitcher).updateWithFilters(before, after, statement, parameters: _*))
  50. case NamedAutoSession(name, _) =>
  51. NamedDB(name, session.settings).autoCommit(DBSessionWrapper(_, attributesSwitcher).updateWithFilters(before, after, statement, parameters: _*))
  52. case ReadOnlyAutoSession =>
  53. DB.readOnly(DBSessionWrapper(_, attributesSwitcher).updateWithFilters(before, after, statement, parameters: _*))
  54. case ReadOnlyNamedAutoSession(name, _) =>
  55. NamedDB(name, session.settings).readOnly(DBSessionWrapper(_, attributesSwitcher).updateWithFilters(before, after, statement, parameters: _*))
  56. case _ =>
  57. DBSessionWrapper(session, attributesSwitcher).updateWithFilters(before, after, statement, parameters: _*)
  58. }
  59. }
  60.  
  61. }

我们也可以把多个SQL语句共同放在一个session-block里:

  1. import org.joda.time._
  2. // DB autoCommit == NamedDB('default) autoCommit
  3. NamedDB('h2mem) autoCommit { implicit session =>
  4. val insertSql: SQL[Nothing,NoExtractor] =
  5. SQL("insert into members (name, birthday, created_at) values (?, ?, ?)")
  6. val createdAt: DateTime = DateTime.now
  7.  
  8. insertSql.bind("Alice", Some(new LocalDate("1980-01-01")), createdAt).update.apply() //commit
  9. insertSql.bind("Bob", None, createdAt).update.apply() //commit
  10. }

这是种批次更新SQL:使用了共同PreparedStatement模版,然后绑定不同的参数进行运算。上面的代码是一种loan-pattern编程模式。除autoCommit还有readOnly,localTx等:

  1. /**
  2. * Provides auto-commit session block.
  3. * @param execution block
  4. * @tparam A return type
  5. * @return result value
  6. */
  7. def autoCommit[A](execution: DBSession => A): A = {
  8. if (autoCloseEnabled) using(conn)(_ => execution(autoCommitSession()))
  9. else execution(autoCommitSession())
  10. }
  11.  
  12. /**
  13. * Provides read-only session block.
  14. * @param execution block
  15. * @tparam A return type
  16. * @return result value
  17. */
  18. def readOnly[A](execution: DBSession => A): A = {
  19. if (autoCloseEnabled) using(conn)(_ => execution(readOnlySession()))
  20. else execution(readOnlySession())
  21. }
  22.  
  23. /**
  24. * Provides local-tx session block.
  25. * @param execution block
  26. * @tparam A return type
  27. * @return result value
  28. */
  29. def localTx[A](execution: DBSession => A)(implicit boundary: TxBoundary[A] = defaultTxBoundary[A]): A = {
  30. val doClose = if (autoCloseEnabled) () => conn.close() else () => ()
  31. val tx = newTx
  32. begin(tx)
  33. val txResult = try {
  34. rollbackIfThrowable[A] {
  35. val session = DBSession(
  36. conn = conn,
  37. tx = Option(tx),
  38. connectionAttributes = connectionAttributes,
  39. settings = this.settingsProvider
  40. )
  41. val result: A = execution(session)
  42. boundary.finishTx(result, tx)
  43. }
  44. } catch {
  45. case e: Throwable => doClose(); throw e
  46. }
  47. boundary.closeConnection(txResult, doClose)
  48. }

在autoCommit域中每一次SQL运算都自动提交事务,不支持交易回滚rollback。在下面的localTx示范里,任何运算出现异常都会导致整体事务的回滚并抛出异常:

  1. //data model
  2. case class Member(
  3. id: Long,
  4. name: String,
  5. description: Option[String] = None,
  6. birthday: Option[LocalDate] = None,
  7. createdAt: DateTime)
  8.  
  9. def create(name: String, birthday: Option[LocalDate], remarks: Option[String])(implicit session: DBSession): Member = {
  10. val insertSQL: SQL[Nothing,NoExtractor] =
  11. sql"""insert into members (name, birthday, description, created_at)
  12. values (${name}, ${birthday}, ${remarks}, ${DateTime.now})"""
  13. val id: Long = insertSQL.updateAndReturnGeneratedKey.apply()
  14. Member(id, name, remarks, birthday,DateTime.now)
  15. }
  16.  
  17. val users = List(
  18. ("John",new LocalDate("2008-03-01"),"youngest user"),
  19. ("Susan",new LocalDate("2000-11-03"),"middle aged user"),
  20. ("Peter",new LocalDate("1983-01-21"),"oldest user"),
  21. )
  22. import scala.util._ //Try
  23. import scalikejdbc.TxBoundary.Try._
  24. val result: Try[List[Member]] =
  25. NamedDB('h2mem) localTx { implicit session =>
  26. Try {
  27. val members: List[Member] = users.map { person =>
  28. create(person._1, Some(person._2), Some(person._3))
  29. }
  30. throw new RuntimeException("fail test. boooommmm!!!!!")
  31. members
  32. }
  33. }
  34.  
  35. result match {
  36. case Success(mlist) => println(s"batch added members: $mlist")
  37. case Failure(err) => println(s"${err.getMessage}")
  38. }

在上面这段代码中localTx block中的所有运算是包嵌在Try{}里的,即交易界限transaction-boundary,任何异常都被框定在这个界限里。以上的例子中不会抛出异常,返回结果包括了运算的所有状态。

我们也可以用case class或其它类型来模拟数据行类型以实现数据行的强类型操作:

  1. //data row converter
  2. val toMember = (rs: WrappedResultSet) => Member(
  3. id = rs.long("id"),
  4. name = rs.string("name"),
  5. description = rs.stringOpt("description"),
  6. birthday = rs.jodaLocalDateOpt("birthday"),
  7. createdAt = rs.jodaDateTime("created_at")
  8. )
  9.  
  10. val selectSQL: SQL[Member,HasExtractor] = sql"""select * from members""".map(toMember)
  11. val members: List[Member] = NamedDB('h2mem) readOnly { implicit session =>
  12. selectSQL.list.apply()
  13. }
  14.  
  15. println(s"all members: $members")
  16. NamedDB('h2mem).close()

上面的代码中使用了sql"""...""",这是标准的scala-string-interpolation,是构建SQL[A,E]的另一种方法。

下面是本次讨论的示范源代码:

  1. import scalikejdbc._
  2. object JDBCIntro extends App {
  3. //standard java procedure to register driver
  4. Class.forName("org.h2.Driver")
  5. //must have a db named 'default
  6. //ConnectionPool.singleton("jdbc:h2:mem:hello", "user", "pass")
  7. //==ConnectionPool.add('default,"jdbc:h2:mem:hello", "user", "pass")
  8. //db name is 'h2mem
  9. ConnectionPool.add('h2mem,"jdbc:h2:mem:hello", "user", "pass")
  10. //construct SQL object
  11. val createSQL: SQL[Nothing,NoExtractor] =SQL("""
  12. create table members (
  13. id bigint primary key auto_increment,
  14. name varchar() not null,
  15. description varchar(),
  16. birthday date,
  17. created_at timestamp not null
  18. )""")
  19.  
  20. //implicit val session = AutoSession 'default
  21. //run this SQL
  22. createSQL.execute().apply()(NamedAutoSession('h2mem)) //autoCommit
  23.  
  24. import org.joda.time._
  25. // DB autoCommit == NamedDB('default) autoCommit
  26. NamedDB('h2mem) autoCommit { implicit session =>
  27. val insertSql: SQL[Nothing,NoExtractor] =
  28. SQL("insert into members (name, birthday, created_at) values (?, ?, ?)")
  29. val createdAt: DateTime = DateTime.now
  30. insertSql.bind("Alice", Some(new LocalDate("1980-01-01")), createdAt).update.apply() //commit
  31. insertSql.bind("Bob", None, createdAt).update.apply() //commit
  32. }
  33.  
  34. //data model
  35. case class Member(
  36. id: Long,
  37. name: String,
  38. description: Option[String] = None,
  39. birthday: Option[LocalDate] = None,
  40. createdAt: DateTime)
  41.  
  42. def create(name: String, birthday: Option[LocalDate], remarks: Option[String])(implicit session: DBSession): Member = {
  43. val insertSQL: SQL[Nothing,NoExtractor] =
  44. sql"""insert into members (name, birthday, description, created_at)
  45. values (${name}, ${birthday}, ${remarks}, ${DateTime.now})"""
  46. val id: Long = insertSQL.updateAndReturnGeneratedKey.apply()
  47. Member(id, name, remarks, birthday,DateTime.now)
  48. }
  49.  
  50. val users = List(
  51. ("John",new LocalDate("2008-03-01"),"youngest user"),
  52. ("Susan",new LocalDate("2000-11-03"),"middle aged user"),
  53. ("Peter",new LocalDate("1983-01-21"),"oldest user"),
  54. )
  55. import scala.util._ //Try
  56. import scalikejdbc.TxBoundary.Try._
  57. val result: Try[List[Member]] =
  58. NamedDB('h2mem) localTx { implicit session =>
  59. Try {
  60. val members: List[Member] = users.map { person =>
  61. create(person._1, Some(person._2), Some(person._3))
  62. }
  63. throw new RuntimeException("fail test. boooommmm!!!!!")
  64. members
  65. }
  66. }
  67.  
  68. result match {
  69. case Success(mlist) => println(s"batch added members: $mlist")
  70. case Failure(err) => println(s"${err.getMessage}")
  71. }
  72.  
  73. //data row converter
  74. val toMember = (rs: WrappedResultSet) => Member(
  75. id = rs.long("id"),
  76. name = rs.string("name"),
  77. description = rs.stringOpt("description"),
  78. birthday = rs.jodaLocalDateOpt("birthday"),
  79. createdAt = rs.jodaDateTime("created_at")
  80. )
  81.  
  82. val selectSQL: SQL[Member,HasExtractor] = sql"""select * from members""".map(toMember)
  83. val members: List[Member] = NamedDB('h2mem) readOnly { implicit session =>
  84. selectSQL.list.apply()
  85. }
  86.  
  87. println(s"all members: $members")
  88. NamedDB('h2mem).close()
  89.  
  90. }

SDP(1):ScalikeJDBC-基本操作介绍的更多相关文章

  1. PyQuery基本操作介绍

    PyQuery基本操作介绍 PyQuery为Python提供一个类似于jQuery对HTML的操作方式,可以使用jQuery的语法对html文档进行查询操作. 本文以百度首页为例来介绍PyQuery的 ...

  2. vim编辑器基本操作介绍

    vim编辑器基本操作介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 可能很多小伙伴都听说过vi编辑器或是vim编辑器.它们是Unix和Linux世界最流行的编辑器之一,他们的特 ...

  3. SpringBoot中Redis的set、map、list、value、实体类等基本操作介绍

    今天给大家介绍一下SpringBoot中Redis的set.map.list.value等基本操作的具体使用方法 上一节中给大家介绍了如何在SpringBoot中搭建Redis缓存数据库,这一节就针对 ...

  4. Activiti工作流(一)之基本操作介绍

    工作流的概念: 工作流(Workflow),就是"业务过程的部分或整体在计算机应用环境下的自动化",它主要解决的是"使在多个参与者之间按照某种预定义的规则传递文档.信息或 ...

  5. 基于MyBatis3.0.6的基本操作介绍

    每 一 个 MyBatis 的 应 用 程 序 都 以 一 个 SqlSessionFactory 对 象 的 实 例 为 核 心 .SqlSessionFactory本身是由SqlSessionFa ...

  6. tensorflow基本操作介绍

    1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始: import tensorflow as tf #定义‘符号’变量,也称为占位符 a = tf. ...

  7. JDBC基本操作介绍

    一 .JDBC主要的API介绍 JDBC为开发人员提供了一套标准的API,都是由JAVA语言编写的类和接口.用于连接数据库和执行SQL语句.JDBC也是JAVA核心类库的一部分,位于Java.sql包 ...

  8. Jquery EasyUI的添加,修改,删除,查询等基本操作介绍

    http://www.jb51.net/article/42016.htm 初识Jquery EasyUI看了一些博主用其开发出来的项目,页面很炫,感觉功能挺强大,效果也挺不错,最近一直想系统学习一套 ...

  9. 【HBase】表模型和基本操作介绍

    目录 HBase表模型 常用Shell操作 HBase表模型 创建一个hbase表,必须要有表名和列族名 列族 -- columnFamily,就是上图中的Column Family1 userInf ...

  10. redis基本操作介绍

    一.字符串 单个设置:set key value,如果key不存在则设置键值对,如果存在则修改 批量设置:mset key1 value1 [key2 value2] 单个获取:get key,如果k ...

随机推荐

  1. cut 命令详解

    cut  作用:按列提取文件 参数: -d 指明列分隔符 -f 选择输出的区域 -c 指定字符位置 -b :以字节为单位进行分割.这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志. -c : ...

  2. Nginx (三) 使用Keepalived搭建高可用服务

    Nginx可以实现高并发反向代理,实现负载均衡,但是有个问题就是Nginx是单点的.如果Nginx故障,则整个服务将会处于不可用状态.所以我们就需要想办法让nginx高可用,即使一个Nginx宕机,还 ...

  3. 发布 Google Chrome插件教程

    换个视角,世界不一样.嘘~~~ 如果你会使用js的话,那么你就可以自己动手写一个chrome插件,而且非常容易.google是一个全球化的平台,想想自己的程序被世界人民所使用,是不是很激动? 注册开发 ...

  4. Odwiedziny[POI 2015]

    题目描述 给定一棵n个点的树,树上每条边的长度都为1,第i个点的权值为a[i]. Byteasar想要走遍这整棵树,他会按照某个1到n的全排列b走n-1次,第i次他会从b[i]点走到b[i+1]点,并 ...

  5. SpringMvc开发步骤

    1.导入基本jar包 2.在Web.xml中配置DispatcherServlet <!-- 配置 DispatcherServlet --> <servlet> <se ...

  6. [Spark內核] 第42课:Spark Broadcast内幕解密:Broadcast运行机制彻底解密、Broadcast源码解析、Broadcast最佳实践

    本课主题 Broadcast 运行原理图 Broadcast 源码解析 Broadcast 运行原理图 Broadcast 就是将数据从一个节点发送到其他的节点上; 例如 Driver 上有一张表,而 ...

  7. Go同步和异步执行多个任务封装

    同步执行类RunnerAsync 支持返回超时检测,系统中断检测 错误常量定义 //超时错误 var ErrTimeout = errors.New("received timeout&qu ...

  8. 自学Aruba之路

    自学Aruba之路[第一回]:体系结构    1.1 自学Aruba1.1-Aruba体系结构-产品线    1.2 自学Aruba1.2-WLAN一些基本常识    1.3 自学Aruba1.3-W ...

  9. Java学习笔记14(面向对象七:final、static)

    final:意为最终,不可变,是一个修饰词 有时候一个类地功能被开发好了,不想让子类重写,修改,这里就会用到final关键字 final修饰类: 不可以被继承,但是可以继承其他类 示例: public ...

  10. ABAP开发人员未来应该学些什么

    2007年1月我大学毕业进入SAP Chengdu从事开发工作,到今天已经整整11年了. 这张图在ABAP开发圈子里曾广为流传: 为了避免这种窘境发生在ABAPer身上,我们应该做点什么呢? 2017 ...