spring xml配置将String转换成Date 类型

	<bean id="customEditorConfigurer"
		  class="org.springframework.beans.factory.config.CustomEditorConfigurer">
		<property name="customEditors">
			<map>
				<entry key="java.util.Date">
					<bean id="MyDateEditor" class="spring.com.MyDateEditor" />
				</entry>
			</map>
		</property>
	</bean>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 添加 mybatis-plus 依赖 ```xml <dependency> <groupId>com.baomidou.mybatisplus</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.2</version> </dependency> ``` 2. 配置数据源 ```yml spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mybatisplus?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: root ``` 3. 配置 mybatis-plus ```java @Configuration @MapperScan("com.example.mapper") public class MybatisPlusConfig { @Autowired private DataSource dataSource; /** * 分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); // 设置方言 paginationInterceptor.setDbType(DbType.MYSQL); return paginationInterceptor; } /** * mybatis-plus SQL执行效率插件【生产环境可以关闭】 */ @Bean @Profile({"dev", "test"}) // 设置 dev test 环境开启 public PerformanceInterceptor performanceInterceptor() { PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor(); performanceInterceptor.setMaxTime(1000); // SQL执行最大时长,超过自动停止运行,有助于发现问题。 performanceInterceptor.setFormat(true); // SQL是否格式化,默认false。 return performanceInterceptor; } @Bean public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() { MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); // 设置mapper文件扫描路径 sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml")); // 设置mybatis配置文件路径 sessionFactory.setConfigLocation(new ClassPathResource("mybatis-config.xml")); // 设置分页插件和SQL执行效率插件 sessionFactory.setPlugins(new Interceptor[]{paginationInterceptor(), performanceInterceptor()}); return sessionFactory; } } ``` 4. 配置实体类和 Mapper ```java @Data public class User { private Long id; private String name; private Integer age; private String email; private Date createTime; private Date updateTime; } @Mapper public interface UserMapper extends BaseMapper<User> { } ``` 5. 使用示例 ```java @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public List<User> list() { return userMapper.selectList(null); } @Override public User getById(Long id) { return userMapper.selectById(id); } @Override public boolean save(User user) { return userMapper.insert(user) > 0; } @Override public boolean update(User user) { return userMapper.updateById(user) > 0; } @Override public boolean removeById(Long id) { return userMapper.deleteById(id) > 0; } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值