当前位置: 首页 > wzjs >正文

有阿里云的主机了怎么做网站wordpress menu_walker

有阿里云的主机了怎么做网站,wordpress menu_walker,信誉好的o2o网站建设,ui设计原理在MyBatis Plus里处理LocalDateTime类型 在MyBatis Plus里处理LocalDateTime类型时,你要确保数据库字段和Java实体类属性之间的类型映射是正确的。下面为你介绍处理这种情况的方法: 1. 数据库字段类型对应设置 要保证数据库字段类型和LocalDateTime相…

在MyBatis Plus里处理LocalDateTime类型

在MyBatis Plus里处理LocalDateTime类型时,你要确保数据库字段和Java实体类属性之间的类型映射是正确的。下面为你介绍处理这种情况的方法:

1. 数据库字段类型对应设置

要保证数据库字段类型和LocalDateTime相适配:

  • MySQL:选用datetime或者timestamp类型。
  • PostgreSQL:使用timestamp类型。
  • Oracle:采用TIMESTAMP类型。

2. 实体类属性配置

在实体类里直接把属性定义成LocalDateTime类型,同时借助MyBatis Plus的注解来映射字段:

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;@TableName("user")
public class User {private Long id;private String name;@TableField("create_time")private LocalDateTime createTime;@TableField("update_time")private LocalDateTime updateTime;// getters and setters
}

3. 配置类型处理器(TypeHandler)

(1)自动配置方式

当你使用的是MyBatis Plus 3.4.0及之后的版本,它能够自动处理LocalDateTime类型,所以一般不用额外配置。

(2)手动配置方式

要是自动配置不满足需求,你可以自定义类型处理器。例如:

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;import java.sql.*;
import java.time.LocalDateTime;@MappedTypes(LocalDateTime.class)
@MappedJdbcTypes(JdbcType.TIMESTAMP)
public class LocalDateTimeTypeHandler extends BaseTypeHandler<LocalDateTime> {@Overridepublic void setNonNullParameter(PreparedStatement ps, int i, LocalDateTime parameter, JdbcType jdbcType) throws SQLException {ps.setTimestamp(i, Timestamp.valueOf(parameter));}@Overridepublic LocalDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {Timestamp timestamp = rs.getTimestamp(columnName);return timestamp != null ? timestamp.toLocalDateTime() : null;}@Overridepublic LocalDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException {Timestamp timestamp = rs.getTimestamp(columnIndex);return timestamp != null ? timestamp.toLocalDateTime() : null;}@Overridepublic LocalDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {Timestamp timestamp = cs.getTimestamp(columnIndex);return timestamp != null ? timestamp.toLocalDateTime() : null;}
}

接着在MyBatis配置文件里注册这个类型处理器:

<typeHandlers><typeHandler handler="com.example.handler.LocalDateTimeTypeHandler"/>
</typeHandlers>

4. 全局配置(可选操作)

你可以在application.yml或者application.properties文件中进行全局配置:

mybatis-plus:configuration:map-underscore-to-camel-case: true# 配置JdbcTypeForNull, oracle数据库必须配置jdbc-type-for-null: 'null'global-config:db-config:logic-not-delete-value: 0logic-delete-value: 1# 配置类型处理器的包路径type-handlers-package: com.example.handler

5. 自动填充功能的实现

如果你想自动填充createTimeupdateTime字段,可以按如下方式操作:

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;import java.time.LocalDateTime;@Component
public class MyMetaObjectHandler implements MetaObjectHandler {@Overridepublic void insertFill(MetaObject metaObject) {this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());}@Overridepublic void updateFill(MetaObject metaObject) {this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());}
}

6. 时间查询示例

下面是使用QueryWrapper进行时间查询的例子:

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.time.LocalDateTime;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public List<User> queryUserByCreateTime(LocalDateTime startTime, LocalDateTime endTime) {QueryWrapper<User> queryWrapper = new QueryWrapper<>();queryWrapper.between("create_time", startTime, endTime);return userMapper.selectList(queryWrapper);}
}

7. 依赖添加

要保证项目中添加了Java 8日期时间支持的依赖:

<!-- MyBatis Plus 依赖 -->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.1</version>
</dependency><!-- mysql 驱动 -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.32</version>
</dependency>

通过上述配置,MyBatis Plus就能顺利处理LocalDateTime类型了,包括数据的读写操作以及自动填充功能。


文章转载自:

http://yx49ZEC4.hmnhp.cn
http://fXq4YUCy.hmnhp.cn
http://8UxNmgmM.hmnhp.cn
http://HOD8YABe.hmnhp.cn
http://dVwyUq89.hmnhp.cn
http://P4YLEes7.hmnhp.cn
http://rr7uPxSb.hmnhp.cn
http://WhRoHUY9.hmnhp.cn
http://0xfan8dc.hmnhp.cn
http://7TJtx9qW.hmnhp.cn
http://ViElT4gY.hmnhp.cn
http://P9C3S810.hmnhp.cn
http://tHpst6LD.hmnhp.cn
http://QTLSOUfW.hmnhp.cn
http://qqaRs9ES.hmnhp.cn
http://LMYh10GY.hmnhp.cn
http://MoRRFpMQ.hmnhp.cn
http://V49kcAJz.hmnhp.cn
http://tJTomkeg.hmnhp.cn
http://PPKhApdM.hmnhp.cn
http://BpfFpZJu.hmnhp.cn
http://3EKrXTyD.hmnhp.cn
http://zn7rXD70.hmnhp.cn
http://99K4mlSr.hmnhp.cn
http://6ZeFMvUz.hmnhp.cn
http://nzK3QmjO.hmnhp.cn
http://jKjpoZHO.hmnhp.cn
http://b43ay6rT.hmnhp.cn
http://ufXAsU0O.hmnhp.cn
http://sTetgKRm.hmnhp.cn
http://www.dtcms.com/wzjs/690272.html

相关文章:

  • 苏州网站开发公司有哪些做淘客要有好的网站
  • 做西餐的网站网站运营名词解释
  • 网站开发实验报告三做网站开发公司电话
  • 企业网站建设市场报价合同管理软件
  • 嘉兴网站推广优化费用wordpress4.7.4+for+sae
  • 广告策划书安阳网站制作优化
  • 精品成品源码网站下载ps软件免费版
  • 吉林省建设工程造价网站WordPress 视频cdn
  • 如何做好一个企业网站童美童程儿童编程价格
  • 所得税 网站建设费公司网站asp源码
  • 网站优化内容wordpress 定时任务怎么开发
  • 做任务得佣金的网站专业建设规划及实施方案
  • 营销网站制作公司推荐皋兰县城乡和住房建设局网站
  • 苏州网站推广排名建设部网站打不开
  • 个人网站 wordpress福建住房和城乡建设部网站
  • 网站设计主色学校北京 代理前置审批 网站备案
  • 重庆网站建设求职简历网络文化经营许可证申请条件
  • 郑州建设银行网站为什么网站不见了
  • 网站建设客户确认单用老域名做网站还是新域名
  • 外贸推广网站网页制作学什么软件好
  • 郴州网站开发公司公司邮箱如何申请
  • 云建造网站网站做md5脚本
  • 大连百度网站快速优化网络服务部工作计划
  • 软件做网站 编程自己写网站建设的业务规划
  • js素材网站做代刷网站赚钱不
  • 莱芜手机网站设计公司最近几年做电影网站怎么样
  • wp如何做网站地图现在最流行的网站开发工具
  • 网站页脚需要放什么谷歌外贸网站
  • 传媒网站制作做网站去哪找客户
  • 长春网站建设方案推广家庭室内装修设计公司