配置目录:
application.properties的配置
#设置服务端口号
server.port = 8090
#配置数据源
spring.datasource.driver-class-name = org.mariadb.jdbc.Driver
spring.datasource.url = jdbc:mariadb://localhost:3306/数据库名
spring.datasource.username = root
spring.datasource.password = 123456
#连接池
spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.type-aliases-package=com.hjb.carsales.entity
mybatis.mapper-locations=classpath:mapper/*.xml
#设置日志
logging.config=classpath:mybatis/logback-spring.xml
#JpaRepository save()加上下面一句话 才起作用
spring.jpa.hibernate.ddl-auto = update
#配置分页
pagehelper.helper-dialect= mariadb
pagehelper.reasonable= true
#如果是mariadb,需要配置如下
spring.jpa.database-platform=org.hibernate.dialect.MariaDB10Dialect
generatorConfig.xml的配置
<!--<properties resource="application.properties" />-->
<context id="main" targetRuntime="MyBatis3Simple">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://localhost:3306/数据库名"
userId="root"
password="123456">
</jdbcConnection>
<javaModelGenerator targetPackage="com.hjb.carsales.entity" targetProject="src\\main\\java">
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="mapper" targetProject="src\\main\\resources">
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.hjb.carsales.dao" targetProject="src\\main\\java">
</javaClientGenerator>
<table tableName="%">
<property name="useActualColumnNames" value="true"/>
<generatedKey column="ID" sqlStatement="JDBC" identity="true" />
</table>
</context>
logback-spring.xml日志配置
<logger name="com.hjb.carsales.dao" level="TRACE" />
<root level="error">
<appender-ref ref="STDOUT" />
</root>
mybatis-config.xml的配置
</dependencies>
插件的配置
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/mybatis/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
跨域配置文件
@Configuration
public class CorsFiter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setHeader("Access-Control-Allow-Origin","http://localhost:8080");
response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS");
response.setHeader("Access-Control-Allow-Credentials","true");
response.setHeader("Access-Control-Max-Age","3600");
response.setHeader("Access-Control-Allow-Headers","X-Requested-with,Content-Type");
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章