Skip to content

Latest commit

 

History

History
394 lines (299 loc) · 9.46 KB

test-page.md

File metadata and controls

394 lines (299 loc) · 9.46 KB

This is a microformat block with images (taken from Getting started with Compose Multiplatform tutorial).

First step Create a Spring Boot project with Kotlin
Second step Add a data class to the Spring Boot project
Third step Add database support for Spring Boot project
Fourth step Use Spring Data CrudRepository for database access>

Synchronized tabs

plugins {
    kotlin("kapt") version "%kotlinVersion%"
}
plugins {
    id "org.jetbrains.kotlin.kapt" version "%kotlinVersion%"
}
plugins {
    kotlin("plugin.noarg") version "%kotlinVersion%"
}
plugins {
    id "org.jetbrains.kotlin.plugin.noarg" version "%kotlinVersion%"
}

Sections

Collapsed section {initial-collapse-state="collapsed"}

Some text here and a codeblock:

plugins {
    kotlin("plugin.noarg") version "%kotlinVersion%"
}

Codeblocks

Just a codeblock:

    import java.util.*

@Service
class MessageService(val db: MessageRepository) {
    fun findMessages(): List<Message> = db.findAll().toList()

    fun findMessageById(id: String): List<Message> = db.findById(id).toList()

    fun save(message: Message) {
        db.save(message)
    }

    fun <T : Any> Optional<out T>.toList(): List<T> =
        if (isPresent) listOf(get()) else emptyList()
}

Expandable codeblock

package com.example.demo

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
    runApplication<DemoApplication>(*args)
}

@RestController
class MessageController {
    @GetMapping("/")
    fun index(@RequestParam("name") name: String) = "Hello, $name!"
}

{initial-collapse-state="collapsed"}

Runnable codeblock

data class User(val name: String, val id: Int)

fun main() {
    val user = User("Alex", 1)
    
    //sampleStart
    // Automatically uses toString() function so that output is easy to read
    println(user)            
    // User(name=Alex, id=1)
    //sampleEnd
}

{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}

Tables

Markdown table

Primitive-type array Equivalent in Java
BooleanArray boolean[]
ByteArray byte[]
CharArray char[]
DoubleArray double[]
FloatArray float[]
IntArray int[]
LongArray long[]
ShortArray short[]

XML table

Last modified on December 2023
Next update June 2024

XML table with codeblocks inside

Simple table:

Before Now
kotlin {
    targets {
        configure(['windows',
            'linux']) {
        }
    }
}
kotlin {
    targets {
        configure([findByName('windows'),
            findByName('linux')]) {
        }
    }
}

More complex table:

Before Now
Dependencies of the jvmMain compilation
jvm<Scope>
jvmCompilation<Scope>
dependencies {
    add("jvmImplementation",
        "foo.bar.baz:1.2.3")
}
dependencies {
    add("jvmCompilationImplementation",
        "foo.bar.baz:1.2.3")
}
Dependencies of the jvmMain source set
jvmMain<Scope>
Dependencies of the jvmTest compilation
jvmTest<Scope>
jvmTestCompilation<Scope>
Dependencies of the jvmTest source set
jvmTest<Scope>

Lists

Ordered list

  1. One

  2. Two

  3. Three

    1. Three point 1
    2. Three point 2
    3. Three point 3
      1. Three point 1 and 1
  4. With a codeblock inside:

    jvmTest<Scope>

Non-ordered list

  • First bullet

  • Second bullet

  • Third bullet

    • One more
    • Another one
      • Wow, one more
  • With a codeblock inside:

    jvmTest<Scope>

Definition list

The return type of the findById() function in the CrudRepository interface is an instance of the Optional class. However, it would be convenient to return a List with a single message for consistency. For that, you need to unwrap the Optional value if it’s present, and return a list with the value. This can be implemented as an extension function to the Optional type.

In the code, Optional<out T>.toList(), .toList() is the extension function for Optional. Extension functions allow you to write additional functions to any classes, which is especially useful when you want to extend functionality of some library class.

This function works with an assumption that the new object doesn’t have an id in the database. Hence, the id should be null for insertion.

If the id isn’t null, CrudRepository assumes that the object already exists in the database and this is an update operation as opposed to an insert operation. After the insert operation, the id will be generated by the data store and assigned back to the Message instance. This is why the id property should be declared using the var keyword.

Text elements

Embedded elements

Video from YouTube