MP的简单使用

编程入门 行业动态 更新时间:2024-10-22 07:29:58

MP的<a href=https://www.elefans.com/category/jswz/34/1770983.html style=简单使用"/>

MP的简单使用

MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

maven依赖

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.0</version>
</dependency>

mapper接口

public interface UserMapper extends BaseMapper<User> {
}

springboot启动类

@SpringBootApplication
@MapperScan("com.luo.springboot01.dao")
public class Springboot01Application {public static void main(String[] args) {SpringApplication.run(Springboot01Application.class, args);}
}

controller层


@Autowired
private UserMapper mapper;//按条件查找,为null就查询全部
@RequestMapping("/select")public List selectOnConditional(User user){List<User> list = mapper.selectList(new QueryWrapper<>(user));return list;}//通过id查询数据
@RequestMapping("/one/{id}")public User selectById(@PathVariable("id")long id){return mapper.selectById(id);
}//通过id删除数据
@RequestMapping("/one/{id}")public int deleteById(@PathVariable("id")long id){int i = mapper.deleteById(id);return i>0?200:-1;}//批量删除
@RequestMapping("/deleteBatchIds")public int deidas(int[] ids){int i = mapper.deleteBatchIds(Arrays.asList(ids));return i>0?200:-1;}//增加对象
@RequestMapping("/add")public int add(User user){int i = mapper.insert(user);return i>0?200:-1;}
//更新
@RequestMapping("/update")public int updateById(User user){int i = mapper.updateById(user);return i>0?200:-1;}

更多推荐

MP的简单使用

本文发布于:2024-03-23 14:45:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1739408.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   MP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!