给MybatisGenerator生成的@Results注解加上id属性

本文介绍如何通过自定义MybatisGenerator插件,在生成的@Results注解中添加id属性,以增强代码的可读性和易用性。通过重写clientSelectByPrimaryKeyMethodGenerated方法并在generatorConfig.xml配置文件中引入插件,最终实现的效果是@Results注解带有类似ResultMap的标识。
摘要由CSDN通过智能技术生成

MybatisGenerator可以很方便地生成dao层代码,一般都是生成xml文件,但MybatisGenerator也可以生成注解,但是有一点不好的是生成的@Results注解没有id属性(图1),这个id属性类似于xml文件里的ResultMap,下面来教大家怎么给生成的@Results注解加上id属性。

图1
图1

定义一个MybatisGenerator的插件,重写clientSelectByPrimaryKeyMethodGenerated方法即可

public class AddResultMapIdPlugin extends PluginAdapter {

	@Override
	public boolean validate(List<String> warnings) {
		return true;
	}


	public boolean clientSelectByPrimaryKeyMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
		List<String> annotations = method.getAnnotations();
		Integer index = annotations.indexOf("@Results({");
		annotat
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值