forked from mybatis/spring-boot-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support Mapper XML based on MyBatis for Spring Boot 3 Native
- Loading branch information
1 parent
c00ce4f
commit d624c02
Showing
29 changed files
with
1,338 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ive-image/org.mybatis.spring.boot/mybatis-spring-boot-autoconfigure/mybatis-resource.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"resources": { | ||
"includes": [ | ||
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-3-config.dtd" }, | ||
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd" }, | ||
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-config.xsd" }, | ||
{ "pattern": "org/apache/ibatis/builder/xml/mybatis-mapper.xsd" } | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/LICENSE_HEADER
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright ${license.git.copyrightYears} the original author or authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
22 changes: 22 additions & 0 deletions
22
mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/format.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015-2024 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE Format> | ||
<Format> | ||
<!-- Dummy format file --> | ||
</Format> |
176 changes: 176 additions & 0 deletions
176
mybatis-spring-boot-samples/mybatis-spring-boot-sample-graalvm-xml/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015-2024 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-samples</artifactId> | ||
<version>3.0.4-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>mybatis-spring-boot-sample-graalvm-xml</artifactId> | ||
<packaging>jar</packaging> | ||
<name>mybatis-spring-boot-sample-graalvm-xml</name> | ||
<properties> | ||
<module.name>org.mybatis.spring.boot.sample.graalvmxml</module.name> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.graalvm.buildtools</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Spring-Boot-Native-Processed>true</Spring-Boot-Native-Processed> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<image> | ||
<builder>paketobuildpacks/builder-jammy-tiny:latest</builder> | ||
<env> | ||
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE> | ||
</env> | ||
</image> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>process-aot</id> | ||
<goals> | ||
<goal>process-aot</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.graalvm.buildtools</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
<version>${native-build-tools-plugin.version}</version> | ||
<configuration> | ||
<classesDirectory>${project.build.outputDirectory}</classesDirectory> | ||
<requiredVersion>22.3</requiredVersion> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>add-reachability-metadata</id> | ||
<goals> | ||
<goal>add-reachability-metadata</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>nativeTest</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.platform</groupId> | ||
<artifactId>junit-platform-launcher</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>process-test-aot</id> | ||
<goals> | ||
<goal>process-test-aot</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.graalvm.buildtools</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
<version>${native-build-tools-plugin.version}</version> | ||
<configuration> | ||
<classesDirectory>${project.build.outputDirectory}</classesDirectory> | ||
<requiredVersion>22.3</requiredVersion> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>native-test</id> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
58 changes: 58 additions & 0 deletions
58
...oot-sample-graalvm-xml/src/main/java/sample/mybatis/graalvm/xml/SampleXmlApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package sample.mybatis.graalvm.xml; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import sample.mybatis.graalvm.xml.dao.CityDao; | ||
import sample.mybatis.graalvm.xml.mapper.CityMapper; | ||
import sample.mybatis.graalvm.xml.mapper.HotelMapper; | ||
|
||
@SpringBootApplication | ||
public class SampleXmlApplication implements CommandLineRunner { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SampleXmlApplication.class, args); | ||
} | ||
|
||
private final CityDao cityDao; | ||
|
||
private final CityMapper cityMapper; | ||
|
||
private final HotelMapper hotelMapper; | ||
|
||
public SampleXmlApplication(CityDao cityDao, CityMapper cityMapper, HotelMapper hotelMapper) { | ||
this.cityDao = cityDao; | ||
this.cityMapper = cityMapper; | ||
this.hotelMapper = hotelMapper; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("squid:S106") | ||
public void run(String... args) { | ||
System.out.println(this.cityDao.selectCityById(1)); | ||
System.out.println(this.cityMapper.findByState("CA")); | ||
System.out.println(this.cityMapper.listByState("ShanDong")); | ||
System.out.println(this.cityMapper.mapByState("CA")); | ||
System.out.println(this.cityMapper.listMapByState("ShanDong")); | ||
System.out.println(this.cityMapper.treeSetStateByState("CN")); | ||
System.out.println(this.cityMapper.hashSetStateByState("CN")); | ||
System.out.println(this.hotelMapper.selectByCityId(1)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...-spring-boot-sample-graalvm-xml/src/main/java/sample/mybatis/graalvm/xml/dao/CityDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package sample.mybatis.graalvm.xml.dao; | ||
|
||
import org.apache.ibatis.session.SqlSession; | ||
import org.springframework.stereotype.Component; | ||
|
||
import sample.mybatis.graalvm.xml.domain.City; | ||
|
||
/** | ||
* @author Eddú Meléndez | ||
*/ | ||
@Component | ||
public class CityDao { | ||
|
||
private final SqlSession sqlSession; | ||
|
||
public CityDao(SqlSession sqlSession) { | ||
this.sqlSession = sqlSession; | ||
} | ||
|
||
public City selectCityById(long id) { | ||
return this.sqlSession.selectOne("selectCityById", id); | ||
} | ||
|
||
} |
Oops, something went wrong.