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

网站建设规划方案ppt启动wordpress linux

网站建设规划方案ppt,启动wordpress linux,精美个人主页,python基础教程百度亿IService 是 MyBatis-Plus 中的一个接口#xff0c;提供了通用的 CRUD 操作#xff0c;简化了数据库操作的代码。下面是 IService 的用法详解及示例代码。 1. 引入依赖 确保在你的 pom.xml 中添加了 MyBatis-Plus 的依赖#xff1a; dependencygroupIdco…IService 是 MyBatis-Plus 中的一个接口提供了通用的 CRUD 操作简化了数据库操作的代码。下面是 IService 的用法详解及示例代码。 1. 引入依赖 确保在你的 pom.xml 中添加了 MyBatis-Plus 的依赖 dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.0/version !-- 请根据实际情况使用最新版本 -- /dependency2. 创建实体类 首先创建一个实体类例如 User import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName;TableName(user) // 指定表名 public class User {TableId // 主键private Long id;private String name;private Integer age;// Getters and Setters }3. 创建 Mapper 接口 创建一个 Mapper 接口继承 BaseMapper import com.baomidou.mybatisplus.core.mapper.BaseMapper;public interface UserMapper extends BaseMapperUser { }4. 创建 Service 接口 创建一个 Service 接口继承 IService import com.baomidou.mybatisplus.extension.service.IService;public interface UserService extends IServiceUser { }5. 创建 Service 实现类 实现 Service 接口 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service;Service public class UserServiceImpl extends ServiceImplUserMapper, User implements UserService {// 可以添加自定义的方法 }6. 使用 Service 在你的 Controller 中使用 UserService import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;import java.util.List;RestController RequestMapping(/users) public class UserController {Autowiredprivate UserService userService;PostMappingpublic boolean saveUser(RequestBody User user) {return userService.save(user);}GetMapping(/{id})public User getUser(PathVariable Long id) {return userService.getById(id);}GetMappingpublic ListUser getAllUsers() {return userService.list();}PutMappingpublic boolean updateUser(RequestBody User user) {return userService.updateById(user);}DeleteMapping(/{id})public boolean deleteUser(PathVariable Long id) {return userService.removeById(id);} }7. 常用方法 IService 提供了一些常用方法包括 save(T entity)保存一个实体removeById(Serializable id)根据 ID 删除updateById(T entity)根据 ID 更新getById(Serializable id)根据 ID 查询list()查询所有记录count()查询总数 总结 通过继承 IService你可以快速实现 CRUD 操作减少了代码量。MyBatis-Plus 还支持很多功能如条件构造器、分页等可以进一步提高开发效率。 在 MyBatis-Plus 中可以在服务实现类中添加自定义方法以实现特定的业务逻辑。下面是如何在 UserServiceImpl 中添加自定义方法的示例。 1. 添加自定义方法到 Service 接口 首先在 UserService 接口中定义你想要的自定义方法。例如我们可以添加一个方法来根据年龄查询用户列表 import java.util.List;public interface UserService extends IServiceUser {ListUser findByAge(Integer age); // 自定义方法 }2. 在 Service 实现类中实现自定义方法 接下来在 UserServiceImpl 中实现这个方法。你可以使用 UserMapper 来执行自定义查询 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service;import java.util.List;Service public class UserServiceImpl extends ServiceImplUserMapper, User implements UserService {// 实现自定义方法Overridepublic ListUser findByAge(Integer age) {QueryWrapperUser queryWrapper new QueryWrapper();queryWrapper.eq(age, age); // 添加条件return this.list(queryWrapper); // 调用基类方法查询} }3. 在 Controller 中使用自定义方法 最后可以在控制器中调用这个自定义方法。例如添加一个新的 API 端点来根据年龄查询用户 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;import java.util.List;RestController RequestMapping(/users) public class UserController {Autowiredprivate UserService userService;// 其他 CRUD 方法...GetMapping(/age/{age})public ListUser getUsersByAge(PathVariable Integer age) {return userService.findByAge(age); // 调用自定义方法} }4. 完整的示例 现在你的 UserService 和 UserServiceImpl 中已经有了自定义方法而 UserController 也可以根据年龄查询用户。以下是最终的代码片段 UserService.java import com.baomidou.mybatisplus.extension.service.IService; import java.util.List;public interface UserService extends IServiceUser {ListUser findByAge(Integer age); // 自定义方法 }UserServiceImpl.java import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import java.util.List;Service public class UserServiceImpl extends ServiceImplUserMapper, User implements UserService {Overridepublic ListUser findByAge(Integer age) {QueryWrapperUser queryWrapper new QueryWrapper();queryWrapper.eq(age, age);return this.list(queryWrapper);} }UserController.java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;import java.util.List;RestController RequestMapping(/users) public class UserController {Autowiredprivate UserService userService;// 其他 CRUD 方法...GetMapping(/age/{age})public ListUser getUsersByAge(PathVariable Integer age) {return userService.findByAge(age);} }总结 通过这种方式你可以轻松地在服务层添加自定义方法利用 MyBatis-Plus 提供的强大功能来实现复杂的业务逻辑。
http://www.dnsts.com.cn/news/198016.html

相关文章:

  • 网站框架一般用什么做手机网站建设的第一个问题
  • 广州网站建设设计厂家大岭山网站
  • 淮安网站建设案例网站seo排名优化工具在线
  • 江苏省建设厅官方网站wordpress主题应用
  • 行业门户网站建设江门网站优化公司
  • 网站vip怎么做狍与女人做爰网站
  • 山东建设厅网站专职安全员wordpress缩略图代码
  • 软件开发用的软件网站优化需要工具
  • 网站说建设中长沙马拉松线上
  • 外贸网站适合用数字域名吗建设快照网站
  • 三只松鼠有趣的软文常宁seo外包
  • 建设简易电子商务网站流程图湄洲岛网站建设
  • 装潢公司网站设计与制作网站开发语音
  • 网站开发行业网站开发数据如何转化
  • 基于互联网 模式下的安全网站建设本地搭建多个网站
  • 网站开发只要东营会计信息网官网首页
  • 微信公众号网站开发wordpress 仿 主题
  • 网上做网站的公司都是怎么做的网站服务器ip
  • 健康门户网站建设内容2023年不用做核酸了吗
  • 站点建设方案免费游戏不用登录的
  • 哪里找专业做网站的人排版设计教程入门初学者
  • 网站主机空间锡盟网站建设
  • 怎么建设网站网站iknowledge wordpress
  • 做油漆的网站什么网站做推广农产品比较好
  • 自己买服务器能在wordpress建网站制作app用什么软件好
  • 网站加入谷歌地图导航吉林省住房和建设厅网站
  • 怎样创建个人的网站dw怎么做网站相册
  • 中国建设银行官网站保本理财wordpress发说说
  • 招远网站建设哪家好现在做推广有什么好的方法
  • 天津品牌网站建设是什么全国免费发布广告信息平台