@SpringBootApplication//(exclude = DataSourceAutoConfiguration.class)
@MapperScan("com.ex.mybatis.generator.mapper")public class GeneratorApplication implements ApplicationRunner{
@Autowired
UserMapper userMapper; public static void main(String[] args) {
SpringApplication.run(GeneratorApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
//generateArtifacts();
User user = new User().withName("123").withCity("abc").withType(13);
userMapper.insert(user);
log.info(user.toString());
UserExample ue = new UserExample();
ue.createCriteria().andCityEqualTo("xxx");
List<User> list = userMapper.selectByExample(ue);
list.forEach(c->log.info(c.toString()));
UserExample ue1 = new UserExample();
ue1.createCriteria().andTypeGreaterThan(80);
list = userMapper.selectByExample(ue1);
list.forEach(c->log.info(c.toString()));
}
注释掉DataSourceAutoConfiguration 报Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
Action:Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
不注释 (exclude = DataSourceAutoConfiguration.class) 报
Action:Consider defining a bean of type 'com.ex.mybatis.generator.mapper.UserMapper' in your configuration.配置为:
<properties resource="application.properties"/>
<classPathEntry location="C:\Users\ex\.m2\repository\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar" />
<context id="MyGeneratorTables" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.FluentBuilderMethodsPlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" /> <jdbcConnection driverClass="${driverClassName}"
connectionURL="${url}"
userId="${username}"
password="${password}">
</jdbcConnection> <javaModelGenerator targetPackage="com.ex.mybatis.generator.model"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <sqlMapGenerator targetPackage="com.ex.mybatis.generator.mapper"
targetProject="./src/main/resources/mapper">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="MIXEDMAPPER"
targetPackage="com.ex.mybatis.generator.mapper"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="hj_user" domainObjectName="User" >
<generatedKey column="id" sqlStatement="CALL IDENTITY()" identity="true" />
</table>
</context>
mybatis.mapper-locations=classpath*:/mapper/**/*.xml
mybatis.type-aliases-package=com.ex.mybatis.generator.model
mybatis.type-handlers-package=com.ex.mybatis.generator.handler
mybatis.configuration.map-underscore-to-camel-case=true
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/hj?useunicode=true&characterEncoding=utf8&serverTimezone=UTC
username=root
password=exspringboot 2.1.4 mybatis-spring-boot-starter2.0.1
@MapperScan("com.ex.mybatis.generator.mapper")public class GeneratorApplication implements ApplicationRunner{
@Autowired
UserMapper userMapper; public static void main(String[] args) {
SpringApplication.run(GeneratorApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
//generateArtifacts();
User user = new User().withName("123").withCity("abc").withType(13);
userMapper.insert(user);
log.info(user.toString());
UserExample ue = new UserExample();
ue.createCriteria().andCityEqualTo("xxx");
List<User> list = userMapper.selectByExample(ue);
list.forEach(c->log.info(c.toString()));
UserExample ue1 = new UserExample();
ue1.createCriteria().andTypeGreaterThan(80);
list = userMapper.selectByExample(ue1);
list.forEach(c->log.info(c.toString()));
}
注释掉DataSourceAutoConfiguration 报Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
Action:Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
不注释 (exclude = DataSourceAutoConfiguration.class) 报
Action:Consider defining a bean of type 'com.ex.mybatis.generator.mapper.UserMapper' in your configuration.配置为:
<properties resource="application.properties"/>
<classPathEntry location="C:\Users\ex\.m2\repository\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar" />
<context id="MyGeneratorTables" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.FluentBuilderMethodsPlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" /> <jdbcConnection driverClass="${driverClassName}"
connectionURL="${url}"
userId="${username}"
password="${password}">
</jdbcConnection> <javaModelGenerator targetPackage="com.ex.mybatis.generator.model"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <sqlMapGenerator targetPackage="com.ex.mybatis.generator.mapper"
targetProject="./src/main/resources/mapper">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="MIXEDMAPPER"
targetPackage="com.ex.mybatis.generator.mapper"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="hj_user" domainObjectName="User" >
<generatedKey column="id" sqlStatement="CALL IDENTITY()" identity="true" />
</table>
</context>
mybatis.mapper-locations=classpath*:/mapper/**/*.xml
mybatis.type-aliases-package=com.ex.mybatis.generator.model
mybatis.type-handlers-package=com.ex.mybatis.generator.handler
mybatis.configuration.map-underscore-to-camel-case=true
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/hj?useunicode=true&characterEncoding=utf8&serverTimezone=UTC
username=root
password=exspringboot 2.1.4 mybatis-spring-boot-starter2.0.1
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货