-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scaffold): suppport mysql and mybatis intergration
- Loading branch information
Showing
11 changed files
with
293 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const _ = require('lodash'); | ||
|
||
module.exports = { | ||
key: 'mybatis', | ||
fn: { | ||
configureProviderPomDependencies (optionalDependencies) { | ||
optionalDependencies.push({ | ||
dependency: [ | ||
{ groupId: 'org.mybatis.spring.boot' }, | ||
{ artifactId: 'mybatis-spring-boot-starter' }, | ||
{ version: '2.0.1' } | ||
] | ||
}) | ||
}, | ||
configureApplicationYaml (yaml, env) { | ||
switch (env) { | ||
case 'default': { | ||
_.merge(yaml, { | ||
mybatis: { | ||
'mapper-locations': 'classpath:mapper/*' | ||
} | ||
}); | ||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
const _ = require('lodash'); | ||
|
||
module.exports = { | ||
key: 'mysql', | ||
fn: { | ||
configureProviderPomDependencies (optionalDependencies) { | ||
optionalDependencies.push({ | ||
dependency: [ | ||
{ groupId: 'mysql' }, | ||
{ artifactId: 'mysql-connector-java' } | ||
] | ||
}) | ||
}, | ||
configureApplicationYaml (yaml, env) { | ||
switch (env) { | ||
case 'default': { | ||
_.merge(yaml, { | ||
spring: { | ||
datasource: { | ||
'driver-class-name': 'com.mysql.jdbc.Driver' | ||
} | ||
} | ||
}); | ||
break; | ||
} | ||
default: { | ||
_.merge(yaml, { | ||
spring: { | ||
datasource: { | ||
username: 'root', | ||
password: 'root', | ||
url: 'jdbc:mysql://127.0.0.1:3306/db_name' | ||
} | ||
} | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...rovider/src/main/java/${basePath}/controller/if_demo_mybatis.CrudDemoController.tmpl.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,22 @@ | ||
package ${basePackage}.controller; | ||
|
||
import ${basePackage}.domain.DemoDo; | ||
import ${basePackage}.service.CrudDemoService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("demo/mybatis") | ||
public class CrudDemoController { | ||
@Autowired | ||
private CrudDemoService service; | ||
|
||
@GetMapping("/") | ||
public List<DemoDo> listAll() { | ||
return service.listAll(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...lates/${artifactId}-provider/src/main/java/${basePath}/domain/if_mybatis.DemoDo.tmpl.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,22 @@ | ||
package ${basePackage}.domain; | ||
|
||
public class DemoDo { | ||
private Long id; | ||
private String name; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...rtifactId}-provider/src/main/java/${basePath}/mapper/if_demo_mybatis.DemoMapper.tmpl.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,13 @@ | ||
package ${basePackage}.mapper; | ||
|
||
import ${basePackage}.domain.DemoDo; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
import java.util.List; | ||
|
||
@Mapper | ||
public interface DemoMapper { | ||
@Select("SELECT * FROM demo") | ||
List<DemoDo> selectAll(); | ||
} |
9 changes: 9 additions & 0 deletions
9
...tId}-provider/src/main/java/${basePath}/service/if_demo_mybatis.CrudDemoService.tmpl.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,9 @@ | ||
package ${basePackage}.service; | ||
|
||
import ${basePackage}.domain.DemoDo; | ||
|
||
import java.util.List; | ||
|
||
public interface CrudDemoService { | ||
List<DemoDo> listAll(); | ||
} |
20 changes: 20 additions & 0 deletions
20
...ider/src/main/java/${basePath}/service/impl/if_demo_mybatis.CrudDemoServiceImpl.tmpl.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,20 @@ | ||
package ${basePackage}.service.impl; | ||
|
||
import ${basePackage}.domain.DemoDo; | ||
import ${basePackage}.mapper.DemoMapper; | ||
import ${basePackage}.service.CrudDemoService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class CrudDemoServiceImpl implements CrudDemoService { | ||
@Autowired | ||
private DemoMapper mapper; | ||
|
||
@Override | ||
public List<DemoDo> listAll() { | ||
return mapper.selectAll(); | ||
} | ||
} |
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