【JavaWeb】SpringMvc+Hibernate+MySql问题集合

1. Spring @ResponseBody返回中文乱码:

配置文件中增加:

    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg value="UTF-8" />
                <property name="writeAcceptCharset" value="false" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

2. Spring 事物自动提交和自动关闭连接

配置文件中加入:

//自动提交事物
<property name="hibernate.connection.autocommit">true</property>
//事物提交之后关闭数据库的连接 
<property name="hibernate.connection.release_mode">after_transaction</property>

3. hql limit 无效

//设置最大结果数
setMaxResults(int max)
//设置查询偏移量
setFirstResults(int first)

4.mysql修改超时时间

同时设置wait_timeout(服务器关闭非交互式连接前的等待时间)和interactive_timeout服务器关闭交互式连接前的等待时间)方可生效


show global variables like  'wait_timeout'

set global wait_timeout=300;

show global variables like  'interactive_timeout';

set global interactive_timeout=300;

5. mysql update整表无效

//错误代码
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

将默认的SQL_SAFE_UPDATES=1改为 SQL_SAFE_UPDATES=0;

 set SQL_SAFE_UPDATES=0;
原文地址:https://www.cnblogs.com/cnsec/p/13286770.html