Browse Source

新增kt的 代码

xiaochan 3 months ago
parent
commit
e5ca4e8144
2 changed files with 90 additions and 0 deletions
  1. 63 0
      pom.xml
  2. 27 0
      src/main/kotlin/thyyxxk/webserver/TestController.kt

+ 63 - 0
pom.xml

@@ -16,6 +16,9 @@
     <properties>
         <java.version>1.8</java.version>
         <druid.version>1.1.10</druid.version>
+        <!-- 添加 Kotlin 版本属性 -->
+        <kotlin.version>2.1.0</kotlin.version>
+
     </properties>
     <dependencies>
         <!--工具类        -->
@@ -248,6 +251,21 @@
             </systemPath>
         </dependency>
 
+
+        <!-- 添加 Kotlin 标准库 -->
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib-jdk8</artifactId>
+            <version>${kotlin.version}</version>
+        </dependency>
+
+        <!-- 添加 Kotlin 反射库 -->
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-reflect</artifactId>
+            <version>${kotlin.version}</version>
+        </dependency>
+
     </dependencies>
 
     <dependencyManagement>
@@ -264,6 +282,51 @@
 
     <build>
         <plugins>
+
+            <plugin>
+                <groupId>org.jetbrains.kotlin</groupId>
+                <artifactId>kotlin-maven-plugin</artifactId>
+                <version>${kotlin.version}</version>
+                <executions>
+                    <execution>
+                        <id>compile</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>test-compile</id>
+                        <phase>test-compile</phase>
+                        <goals>
+                            <goal>test-compile</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <jvmTarget>${java.version}</jvmTarget>
+                    <args>
+                        <arg>-Xjsr305=strict</arg> <!-- 启用严格的空安全检查 -->
+                    </args>
+                </configuration>
+            </plugin>
+
+            <!-- 确保 Kotlin 编译在 Java 之前 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <executions>
+                    <execution>
+                        <id>compile</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>

+ 27 - 0
src/main/kotlin/thyyxxk/webserver/TestController.kt

@@ -0,0 +1,27 @@
+package thyyxxk.webserver
+
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RestController
+import thyyxxk.webserver.config.auth.PassToken
+import thyyxxk.webserver.dao.his.xcTest.TestDao
+import thyyxxk.webserver.entity.ResultVo
+import thyyxxk.webserver.utils.R
+
+@RestController
+@RequestMapping("/kt/test")
+class TestController(private val testDao: TestDao) {
+    companion object {
+        private val log: Logger = LoggerFactory.getLogger(TestController::class.java)
+    }
+
+
+    @GetMapping("/test1")
+    @PassToken
+    fun test(): ResultVo<String> {
+        val patientInfo = testDao.patientInfo("506388023")
+        return R.ok("TEST")
+    }
+}