mybatis puls一些关键点技巧和注意

mybatis puls一些关键点技巧和注意,第1张

官网地址https://baomidou.com/

@TableField(exist = false)放在javabeen的属性下
表示表字段没有值该值,前端传了也没事
    @TableField(exist = false)
    

当前端传来teacherForm 而我们been 为teacher
持久化teacher 需要teacherForm 的值时
BeanUtils.copyProperties() 可以把
teacherForm teacher 相同的属性合并
如果Teacher和TeacherForm间存在名称不相同的属性,则BeanUtils不对这些属性进行处理,

BeanUtils.copyProperties(teacher,teacherForm);   

使用分页和LambdaQueryWrapper 条件 需要 加入${ew.customSqlSegment和}打开分页插件


@EnableTransactionManagement
public class MybatisPlusConfig {

    @Bean
    public static MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
        // 1.设置使用的会话工厂
        //configurer.setSqlSessionFactoryBeanName("sessionFactory");
        // 2.配置扫描的映射接口
        configurer.setBasePackage("com.xiaoben.nuxt");
        // 3.指定组件类型
        configurer.setAnnotationClass(Mapper.class);
        return configurer;
    }

    /**
     * 分页插件
     // 最新版
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

map 层----------




public interface AssetCategoryMapper extends MPJBaseMapper<AssetCategory> {



        @Select("SELECT * FROM xb_asset_category ${ew.customSqlSegment}" )
        Page<AssetCategory>  getpage(Page<AssetCategory> page,@Param(Constants.WRAPPER) LambdaQueryWrapper<AssetCategory> q);
}

Service实现类




 */
@Service
public class AssetCategoryServiceImpl extends ServiceImpl<AssetCategoryMapper, AssetCategory> implements AssetCategoryService {



    @Override
    public Object getlist() {

        LambdaQueryWrapper<AssetCategory> q=new LambdaQueryWrapper<>();
        q.gt(AssetCategory::getId,3);
        Page<AssetCategory> page = new Page<>(1,2);

        return baseMapper.getpage(page, q);
    }
}

Controller层

@RestController
@RequestMapping("/dd")
public class AssetCategoryController {


    @Autowired
    private AssetCategoryService assetCategoryService;
 @GetMapping ("yd")
    public Object ccn(  ){



        return   assetCategoryService.getlist();
    }
    }

条件语句大全

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/797511.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存