文章目录
- 1.数据库的一些问题
- 1.数据库自动生成主键id
- 2.MySQL数据库自动生成时间
- 3.根据当前时间与数据库的某个时间相差了多少天
- 4.使用MySQL创建触发器时出错:
- 2.ssm框架使用pagehelper
1.数据库的一些问题
1.数据库自动生成主键id
通过idea连接数据库,然后把主键的id设置成int类型,然后把Auto inc勾打上即可
2.MySQL数据库自动生成时间
1.方法一:
1、将字段类型设为 TIMESTAMP
2、将默认值设为 CURRENT_TIMESTAMP
不需要打勾auto inc
3.根据当前时间与数据库的某个时间相差了多少天
SELECT DATEDIFF(now(),数据库某个时间字段) as 相差时间 ,其他字段 from 数据库表 where xxx='xxx';
4.使用MySQL创建触发器时出错:
You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
解决方法:
第一步,用root用户登录:mysql -u root -p
第二步,设置参数log_bin_trust_function_creators为1:set global log_bin_trust_function_creators = 1;
1.查看已经创建的触发器
SHOW TRIGGERS ;
2.删除已经创建的触发器
DROP TRIGGER 触发器名字;
2.ssm框架使用pagehelper
1.在pom.xml引入依赖
<!--引入分页插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.2.0</version></dependency></dependencies>
2.在spring配置文件中进入
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 注意其他配置 --><property name="dataSource" ref="dataSource" /><property name="configLocation" value="classpath:conf/mybatis.xml" /><property name="plugins"><array><bean class="com.github.pagehelper.PageInterceptor"><property name="properties"><props><prop key="helperDialect">mysql</prop><prop key="reasonable">true</prop></props></property></bean></array></property></bean>
3.注意,使用分页插件时,SQL查询语句后不能加";",否则报错
因为limit语句出现在;后面不合法,如: select * from table ; LIMIT ?