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

手机智能建网站关键词排名优化怎么样

手机智能建网站,关键词排名优化怎么样,九天传说超变单职业传奇页游,做网站用哪种语言好简介 MyBatisPlus 是 MyBatis 的一个增强工具,主要简化了 MyBatis 的开发工作,提高了开发效率。提供 CRUD 接口、条件构造器、自动分页、代码生成等功能,大大减少了重复代码的编写。 官方文档:简介 | MyBatis-Plus 视频&#x…

简介

MyBatisPlus 是 MyBatis 的一个增强工具,主要简化了 MyBatis 的开发工作,提高了开发效率。提供 CRUD 接口、条件构造器、自动分页、代码生成等功能,大大减少了重复代码的编写。

官方文档:简介 | MyBatis-Plus

视频:黑马程序员——MybatisPlus

 文档:黑马程序员 —— MybatisPlus

替换mybatis

1.更改pom.xml中的依赖项

<!--
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.3.1</version>
</dependency>
--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.1</version>
</dependency>

2.继承BaseMapper类,泛型中写实体类,同时删掉原有方法,后续可以直接调用BaseMapper类的方法进行数据库的增删改查。

3.更改测试类中的方法,即将前面删掉的方法,改为调用BaseMapper类的方法,如下注释后的更改。

常用注解

@TableName 用于指定数据库表的名称

如果是驼峰对应转换的话可以不写,比如类名User对应表名user。

@TableName("users")
public class User {// ...
}

@TableId 用于指定表的主键字段,并配置主键生成策略。

属性:1.value:主键字段名。2.type:主键生成策略,如 IdType.AUTO(数据库自增)、IdType.INPUT(手动输入)、IdType.ASSIGN_ID(默认雪花算法生成ID)等。

@TableId("id")
private Long id;
@TableId(value = "id", type = IdType.AUTO)
private Long id;

@TableField 用于指定非主键字段,并配置字段属性。

 属性:1.value:数据库字段名。2.exist:是否为数据库表中字段,默认为 true。3.fill:字段自动填充策略,如 FieldFill.INSERT(插入时填充)、FieldFill.UPDATE(更新时填充)、FieldFill.INSERT_UPDATE(插入和更新时填充)。

如果是驼峰对应转换的话可以不写,比如userName对应user_name。

@TableField("name")
private String userName;

如果不是驼峰对应转换的话必须使用注解。

如果表中不存在对应的话一定要标注非表中字段。

如果用到了数据库的关键字比如order那就必须使用注解;

如果存在布尔变量比如isMarried,它会认为对应表中的married而不是is_married,此时也必须使用注解。

常用配置

随用随记即可,大部分继承自mybatis。

条件构造器

直接通过案例理解,先写出sql语句,再实现需求。

1.QueryWrapper(类名)

运行测试方法,可以看到最终执行的sql注入语句是对的。

2.UpdateWrapper

3.LambdaQueryWrapper

QueryWrapper的不同点在于,使用反射构建查询条件wrapper,避免硬编码。会有一行警告,是因为使用了反射机制。但是sql语句和查询结果正常。

自定义sql

1.先看下目录,可以将测试类中的方法看成在业务层中实现功能。

2.业务层实现方法,将条件传递到mapper代理层。

3.mappper层声明方法,参数前需要加上注解,可以用"ew"也可以用Constants.WRAPPER。

4.在xml配置文件中将其拼接,注意一个是#一个是$,并且$前必须有空格。

5.运行该方法,可以看到sql语句拼接成功。

Iservice接口基本用法

可以避免写一些基础的增删改查的sql语句,而是直接调用方法。

1.先看目录,业务层和测试层。

2.接口IUserService继承IService接口,泛型为实体类User。

3.IUserServiceImpl类继承ServiceImpl类,泛型为代理层UserMapper和实体类User,并实现IUserService接口。

4.实现测试类,测试插入和查询,均测试成功。

IService开发基础业务接口

对于简单接口,不用写service代码,直接调用mybatisplus的方法即可实现。

1.先看目录,实现dto和vo。dto是接收到的数据类型,po是和数据库的表字段相对应的实体类,vo是要返回的数据类型。

package com.itheima.mp.domain.dto;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;@Data
@ApiModel(description = "用户表单实体")
public class UserFormDTO {@ApiModelProperty("id")private Long id;@ApiModelProperty("用户名")private String username;@ApiModelProperty("密码")private String password;@ApiModelProperty("注册手机号")private String phone;@ApiModelProperty("详细信息,JSON风格")private String info;@ApiModelProperty("账户余额")private Integer balance;
}
package com.itheima.mp.domain.vo;import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;@Data
@ApiModel(description = "用户VO实体")
public class UserVO {@ApiModelProperty("用户id")private Long id;@ApiModelProperty("用户名")private String username;@ApiModelProperty("详细信息")private String info;@ApiModelProperty("使用状态(1正常 2冻结)")private Integer status;@ApiModelProperty("账户余额")private Integer balance;
}

2.修改pom.xml引入依赖。Swagger 是一个广泛使用的开源框架,用于设计、构建、记录和使用 RESTful Web 服务,提供了一套完整的工具和规范,使 API 的开发和维护更加简单和高效。

<!--swagger-->
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi2-spring-boot-starter</artifactId><version>4.1.0</version>
</dependency>
<!--web-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>

3.在application.yaml中添加配置swagger信息。

knife4j:enable: true  # 启用 Knife4j 接口文档生成工具openapi:title: 用户管理接口文档  # API 文档的标题description: "用户管理接口文档"  # API 文档的描述email: zhanghuyi@itcast.cn  # 联系人的电子邮件地址concat: 虎哥  # 联系人名称url: https://www.itcast.cn  # 联系人的 URLversion: v1.0.0  # API 文档的版本号group:default:group-name: default  # API 组名称api-rule: package  # API 分组规则,这里按包名进行分组api-rule-resources:- com.itheima.mp.controller  # 需要生成文档的控制器包名

4.实现以下四个接口。

package com.itheima.mp.controller;import cn.hutool.core.bean.BeanUtil;
import com.itheima.mp.domain.dto.UserFormDTO;
import com.itheima.mp.domain.po.User;
import com.itheima.mp.domain.vo.UserVO;
import com.itheima.mp.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;import java.util.List;@Api(tags = "用户管理接口") // Swagger 注解,标记该类为用户管理接口
@RequestMapping("/users") // 定义请求路径为 /users
@RestController // 标记该类为 RESTful 控制器
@RequiredArgsConstructor // Lombok 注解,生成带有 final 字段的构造函数
public class UserController {private final IUserService iUserService; // 注入 IUserService,使用构造函数注入@ApiOperation("新增用户接口") // Swagger 注解,描述该方法的用途@PostMapping // 定义 POST 请求public void saveUser(@RequestBody UserFormDTO userFormDTO) { // @RequestBody 注解表示请求体中的 JSON 将被反序列化为 UserFormDTO 对象// 使用 BeanUtil.copyProperties 将 UserFormDTO 转换为 User 实体User user = BeanUtil.copyProperties(userFormDTO, User.class);// 调用服务层的保存方法iUserService.save(user);}@ApiOperation("删除用户接口")@DeleteMapping("{id}")public void deleteUserById(@ApiParam("用户id") @PathVariable("id") long id) {iUserService.removeById(id);}@ApiOperation("根据id查询用户接口")@GetMapping("{id}")public UserVO queryUserById(@ApiParam("用户id") @PathVariable("id") long id) {// 1.查询用户poUser user = iUserService.getById(id);// 2.把po拷贝到voreturn BeanUtil.copyProperties(user, UserVO.class);}@ApiOperation("根据id批量查询用户接口")@GetMappingpublic List<UserVO> queryUserByIds(@ApiParam("用户id集合") @PathVariable("ids") List<Long> ids) {// 1.查询用户poList<User> users = iUserService.listByIds(ids);// 2.把po拷贝到voreturn BeanUtil.copyToList(users, UserVO.class);}
}

Iservice开发复杂业务接口

对于复杂的业务以及需要编写自定义sql语句,依然需要自定义service层方法,并在其中调用mapper层方法。

比如根据id扣减余额,需要先判断余额是否足够,因此先查询后再做决定。

1.先看目录。

2.在UserController.java中添加方法。

 @ApiOperation("根据id扣减用户余额接口")@PutMapping("/{id}/deduction/{money}")public void deductBalanceBuId(@ApiParam("用户id") @PathVariable("id") Long id,@ApiParam("用户id") @PathVariable("money") Integer money) {iUserService.deductBalanceBuId(id, money);}

3.在接口IUserService.java中声明方法并在IUserServiceImpl.java中实现

package com.itheima.mp.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.itheima.mp.domain.po.User;public interface IUserService extends IService<User> {void deductBalanceBuId(Long id, Integer money);
}
package com.itheima.mp.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mp.domain.po.User;
import com.itheima.mp.mapper.UserMapper;
import com.itheima.mp.service.IUserService;
import org.springframework.stereotype.Service;@Service
public class IUserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {@Overridepublic void deductBalanceBuId(Long id, Integer money) {// 1.查询用户User user = getById(id);// 2.校检用户状态if (user == null || user.getStatus() == 2) {throw new RuntimeException("用户状态异常!");}// 3.校检余额是否充足if (user.getBalance() < money) {throw new RuntimeException("用户余额不足!");}// 4.扣减余额 update user set balance = balance - #{money} where id = #{id}//user.setBalance(user.getBalance() - money);baseMapper.deductBalance(id, money);}
}

4.在UserMapper.java中添加方法,使用注解添加sql语句。

package com.itheima.mp.mapper;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.itheima.mp.domain.po.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;public interface UserMapper extends BaseMapper<User> {void updateBalance(@Param("amount") int amount, @Param(Constants.WRAPPER) QueryWrapper<User> wrapper);@Update("update user set balance = balance - #{money} where id = #{id}")void deductBalance(@Param("id") Long id, @Param("money") Integer money);/*void saveUser(User user);void deleteUser(Long id);void updateUser(User user);User queryUserById(@Param("id") Long id);List<User> queryUserByIds(@Param("ids") List<Long> ids);*/
}

5.点击左下方图标或者快捷键Alt+8打开服务,点击+号选择springboot添加启动项,点击启动图标,再点击红色方框中的8080打开网页。

6.添加/doc.html后缀,即http://localhost:8080/doc.html,访问即可看到swagger生成的api文档,可测试各个接口。

IService的批量新增

(by 归忆)


文章转载自:
http://bodywork.bpcf.cn
http://primate.bpcf.cn
http://dithery.bpcf.cn
http://naif.bpcf.cn
http://travail.bpcf.cn
http://redemandable.bpcf.cn
http://irascible.bpcf.cn
http://mac.bpcf.cn
http://fbi.bpcf.cn
http://tamil.bpcf.cn
http://bravo.bpcf.cn
http://washeteria.bpcf.cn
http://bashlyk.bpcf.cn
http://scouse.bpcf.cn
http://earthing.bpcf.cn
http://goatsucker.bpcf.cn
http://scorer.bpcf.cn
http://colette.bpcf.cn
http://shivering.bpcf.cn
http://nitroguanidine.bpcf.cn
http://unswayed.bpcf.cn
http://allseed.bpcf.cn
http://vindicatory.bpcf.cn
http://ibsenism.bpcf.cn
http://pangene.bpcf.cn
http://fisheye.bpcf.cn
http://insurer.bpcf.cn
http://namesake.bpcf.cn
http://torchon.bpcf.cn
http://mythological.bpcf.cn
http://minisub.bpcf.cn
http://kreisler.bpcf.cn
http://api.bpcf.cn
http://anestrus.bpcf.cn
http://authorless.bpcf.cn
http://jonesian.bpcf.cn
http://cochlea.bpcf.cn
http://dosimetry.bpcf.cn
http://christchurch.bpcf.cn
http://undivulged.bpcf.cn
http://antiterrorism.bpcf.cn
http://unlisted.bpcf.cn
http://idiophone.bpcf.cn
http://eolith.bpcf.cn
http://whomsoever.bpcf.cn
http://appealing.bpcf.cn
http://negatron.bpcf.cn
http://briquette.bpcf.cn
http://accomplice.bpcf.cn
http://unalleviated.bpcf.cn
http://intermezzo.bpcf.cn
http://fibrillate.bpcf.cn
http://tacheometry.bpcf.cn
http://perversity.bpcf.cn
http://exultant.bpcf.cn
http://rotissomat.bpcf.cn
http://swollen.bpcf.cn
http://refractional.bpcf.cn
http://autism.bpcf.cn
http://quadrupedal.bpcf.cn
http://presentiment.bpcf.cn
http://tunguz.bpcf.cn
http://magistrate.bpcf.cn
http://midget.bpcf.cn
http://begun.bpcf.cn
http://nuthatch.bpcf.cn
http://backwater.bpcf.cn
http://canaliculated.bpcf.cn
http://auteur.bpcf.cn
http://ariot.bpcf.cn
http://thanatophoric.bpcf.cn
http://timeserver.bpcf.cn
http://krim.bpcf.cn
http://caseose.bpcf.cn
http://basan.bpcf.cn
http://talipot.bpcf.cn
http://claustrophobe.bpcf.cn
http://embedded.bpcf.cn
http://obturate.bpcf.cn
http://magian.bpcf.cn
http://ouroscopy.bpcf.cn
http://coadjust.bpcf.cn
http://genitive.bpcf.cn
http://soupcon.bpcf.cn
http://synod.bpcf.cn
http://bluejeans.bpcf.cn
http://lilacky.bpcf.cn
http://oinochoe.bpcf.cn
http://undernote.bpcf.cn
http://felicitously.bpcf.cn
http://flossie.bpcf.cn
http://ecmnesia.bpcf.cn
http://inflame.bpcf.cn
http://bricky.bpcf.cn
http://pleistocene.bpcf.cn
http://townsville.bpcf.cn
http://fucoid.bpcf.cn
http://oropharynx.bpcf.cn
http://symptomatic.bpcf.cn
http://pazazz.bpcf.cn
http://www.15wanjia.com/news/102199.html

相关文章:

  • 导购网站怎么建域名注册哪个网站好
  • flash个人网站设计小程序开发
  • wordpress填写数据库seo优化的作用
  • 做网站工作描述网址导航
  • 制做网站的公司软文推广哪个平台好
  • 怎么推广游戏代理赚钱2022年百度seo
  • 天津酒店网站制作农业推广
  • 做公司网站首页搜索引擎优化规则
  • 平面设计做画册用网站河南智能seo快速排名软件
  • 网站做seo收录官方百度
  • 网站使用功能介绍是用什么软件做的宁波优化seo软件公司
  • 网站建设打造学院百度广告代理商查询
  • 电商详情页用什么软件做的营销排名seo
  • python在线播放seo运营
  • blog网站设计抖音seo优化怎么做
  • asp网站制作实例教程知名seo公司
  • 资讯网站做app排名优化公司
  • 网站建设公司哪好站长交流平台
  • 中国建设银行绑定网站爱站网ip反查域名
  • python 网站开发流程图上海做网站优化
  • 给前端做网站的图片叫什么软件引流获客工具
  • 网站app开发哪家好品牌营销方案
  • 网站快速排名是怎么做的2022年最火文案
  • 静态网站 站内搜索工业设计公司
  • 如何用ps做网站ui雅虎搜索引擎首页
  • 中国代理网官网站长之家seo信息
  • 唐山地方志网站建设青岛专业网站制作
  • 做网站最下面写什么搜索引擎优化的概念
  • 建站赚钱灰色超级软文网
  • 定制v下载安卓seo怎么优化软件