使用Mybatis Plus时出现的问题(2019/3/21)
①中文乱码
连接的属性编码直接使用 ‘自动’。
数据库和表设置UTF-8编码。
同时JDBC接连地址使用UTF-8编码:
jdbc.jdbcUrl=jdbc:mysql:///ssm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT
(PS:使用Druid数据源,和Mysql8版本)
②Mybatis Plus新版本使用(Mybatis Plus版本3.1.0(Feb 24, 2019))。
其spring的xml配置文件需要如下(部分):
<bean id="mybatisSqlSessionFactoryBean" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<!--加载数据库连接-->
<property name="dataSource" ref="dataSource"/>
<!--指定mapper文件-->
<property name="mapperLocations" value="classpath*:edu/hut/hz/mapper/*.xml" />
<!--加载Mybatis配置文件-->
<property name="configLocation" value="classpath:mybatis.xml"/>
<!--加载MybatisPlus全局策略配置-->
<property name="globalConfig" ref="globalConfiguration"/>
</bean>
<!-- 定义MybatisPlus的全局策略配置 -->
<bean id="globalConfiguration" class="com.baomidou.mybatisplus.core.config.GlobalConfig">
<property name="dbConfig">
<bean class="com.baomidou.mybatisplus.core.config.GlobalConfig.DbConfig">
<!--主键规则-->
<property name="idType" value="AUTO"/>
<!--表前缀-->
<!--<property name="tablePrefix" value="tbl_"/>-->
</bean>
</property>
<property name="sqlInjector" ref="logicalDelInjector"/>
</bean>
<!--防止SQL注入-->
<bean id="logicalDelInjector" class="com.baomidou.mybatisplus.extension.injector.LogicSqlInjector"/>