电子商务网站成本,网站推广服务方案,html代码中标签的书写不区分大小写,wordpress收费下载资源插件一、mybtis-plus配置下载 MyBatis-Plus 是一个 Mybatis 增强版工具#xff0c;在 MyBatis 上扩充了其他功能没有改变其基本功能#xff0c;为了简化开发提交效率而存在。 具体的介绍请参见官方文档。 官网文档地址#xff1a;mybatis-plus
添加mybatis-plus依赖
depe…一、mybtis-plus配置下载 MyBatis-Plus 是一个 Mybatis 增强版工具在 MyBatis 上扩充了其他功能没有改变其基本功能为了简化开发提交效率而存在。 具体的介绍请参见官方文档。 官网文档地址mybatis-plus
添加mybatis-plus依赖
dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.1/version
/dependency添加MyBatisPlusConfig配置文件
config包中添加MyBatisPlusConfig配置文件将原来在mapper中的mapper注解取消继承上BaseMapper泛型接口即可。 Mybatis-Plus里的BaseMapper接口自带crud功能继承了BaseMapper接口的接口.。 代码如下
package com.example.demo.config;import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
MapperScan(com.example.demo.demos.web.demo.mapper)
public class MyBatisPlusConfig {//配置分页插件Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();//数据库类型是MySql因此参数填写DbType.MYSQLinterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}}mapper 中如下配置 3. yml 中写如下配置 mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl二、mybtis-plus实现增删改查
数据增加或修改 在这里插入图片描述
结果 修改 注意映射表不要瞎加字段否则容易出现异常 Error querying database. Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘page_num’ in ‘field list’
所有代码 config
package com.example.demo.config;import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
MapperScan(com.example.demo.demos.web.demo.mapper)
public class MyBatisPlusConfig {//配置分页插件Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();//数据库类型是MySql因此参数填写DbType.MYSQLinterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));return interceptor;}}controller package com.example.demo.demos.web.demo.controller;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.demos.web.demo.entity.UserEntity;
import com.example.demo.demos.web.demo.mapper.UserMapper;
import com.example.demo.demos.web.demo.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;import java.util.HashMap;
import java.util.List;
import java.util.Map;RestController
RequestMapping(user)
public class UserController {// Autowired// private UserMapper userMapper;Autowiredpublic UserService userService;
/* GetMapping(/)public ListUserEntity index(){return userMapper.findAll();}*///使用mybtis-plus实现查询所有数据GetMapping(/)public ListUserEntity findAll(){return userService.list();}/* PostMapping(/add)//这里做了一个单纯的添加的示例使用的是mapper中的insert方法public Integer save(RequestBody UserEntity userEntity){return userService.save(userEntity);}*//* DeleteMapping(/{id})public Integer deleteById(PathVariable Integer id){return userService.deleteById(id);}*///使用mybtis-plus实现删除DeleteMapping(/{id})public boolean deleteById(PathVariable Integer id){return userService.removeById(id);}PostMapping(/add)//使用mybtis-plus,注意这里返回的是boolean型public Boolean save(RequestBody UserEntity user) {return userService.saveUser(user);}//分页查询//接口路径user/page?pageNum1pageSize10//RequestParam接受前台传过来的第几页每页显示数
/* GetMapping(/page)public MapString,Object findPage(RequestParam Integer pageNum,RequestParam Integer pageSize){pageNum(pageNum-1)*pageSize;ListUserEntity datauserService.selectPage(pageNum,pageSize);Integer totaluserMapper.selectTotal();MapString,Object resnew HashMap();res.put(data,data);res.put(total,total);return res;}*///使用mybtis-plus实现根据ID查找记录GetMapping(/{id})public UserEntity findOne(PathVariable Integer id){return userService.getById(id);}//使用mybtis-plus实现模糊查询并分页GetMapping(/page)public IPageUserEntity findPage(RequestParam Integer pageNum,RequestParam Integer pageSize,RequestParam(defaultValue ) String username,RequestParam(defaultValue ) String nickname,RequestParam(defaultValue ) String address){IPageUserEntity pagenew Page(pageNum,pageSize);QueryWrapperUserEntity queryWrappernew QueryWrapper();queryWrapper.like(username,username);queryWrapper.like(nickname,nickname);queryWrapper.like(address,address);return userService.page(page,queryWrapper);}}entity
package com.example.demo.demos.web.demo.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;Data
NoArgsConstructor
AllArgsConstructor
TableName(valuesys_user)
public class UserEntity {TableId(value id,type IdType.AUTO)private Integer id;
/* private Integer pageNum;private Integer pageSize;*/private String username;private String password;private String email;private String phone;private String nickname;private String address;private String create_time;private String avatar;private String role;}
mapper
package com.example.demo.demos.web.demo.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.demos.web.demo.entity.UserEntity;
import org.apache.ibatis.annotations.*;import java.util.List;//Mapper 前面配置文件中已经配置 这个注解可以注销但是要继承接口
public interface UserMapper extends BaseMapperUserEntity {/* Select(select * from sys_user limit #{pageNum},#{pageSize})ListUserEntity selectPage(Param(pageNum) Integer pageNum,Param(pageSize) Integer pageSize);//Select(select * from sys_user limit #{pageNum},#{pageSize})Select(select * from sys_user)ListUserEntity findAll();Insert(insert into sys_user(username,password,email,phone,nickname,address,avatar,role) VALUES(#{username},#{password},#{email},#{phone},#{nickname},#{address},#{avatar},#{role});)//这里只是做测试使用int insert(UserEntity userEntity);int update(UserEntity userEntity);Delete(delete from sys_user where id#{id})int deleteById(Param(id) Integer id);*/// 记录总数/* Select(select count(*) from sys_user)Integer selectTotal();
*/}service
package com.example.demo.demos.web.demo.service;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.demos.web.demo.entity.UserEntity;
import com.example.demo.demos.web.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;Service
public class UserService extends ServiceImplUserMapper, UserEntity {// Autowired// private UserMapper userMapper;/* public int save(UserEntity userEntity){//如果user没有id则表明是新增if(userEntity.getId()null){return userMapper.insert(userEntity);}//否则就是更新else {return userMapper.update(userEntity);}}*/public Boolean saveUser(UserEntity userEntity){return saveOrUpdate(userEntity);}/* public Integer deleteById(Integer id) {return userMapper.deleteById(id);}*/// 分页查找/* public List selectPage(Integer pageNum, Integer pageSize) {return userMapper.selectPage(pageNum,pageSize);}*/}
项目架构 文章转载自: http://www.morning.xhqr.cn.gov.cn.xhqr.cn http://www.morning.xshkh.cn.gov.cn.xshkh.cn http://www.morning.zwyuan.com.gov.cn.zwyuan.com http://www.morning.hrtwt.cn.gov.cn.hrtwt.cn http://www.morning.rahllp.com.gov.cn.rahllp.com http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.wnnfh.cn.gov.cn.wnnfh.cn http://www.morning.yxbrn.cn.gov.cn.yxbrn.cn http://www.morning.ntqlz.cn.gov.cn.ntqlz.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn http://www.morning.sltfk.cn.gov.cn.sltfk.cn http://www.morning.ctxt.cn.gov.cn.ctxt.cn http://www.morning.szoptic.com.gov.cn.szoptic.com http://www.morning.qrksj.cn.gov.cn.qrksj.cn http://www.morning.dfltx.cn.gov.cn.dfltx.cn http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn http://www.morning.gtwtk.cn.gov.cn.gtwtk.cn http://www.morning.qpqwd.cn.gov.cn.qpqwd.cn http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.cjxqx.cn.gov.cn.cjxqx.cn http://www.morning.zcfsq.cn.gov.cn.zcfsq.cn http://www.morning.qztsq.cn.gov.cn.qztsq.cn http://www.morning.kjcll.cn.gov.cn.kjcll.cn http://www.morning.lthgy.cn.gov.cn.lthgy.cn http://www.morning.pcbfl.cn.gov.cn.pcbfl.cn http://www.morning.rjtmg.cn.gov.cn.rjtmg.cn http://www.morning.pudejun.com.gov.cn.pudejun.com http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.xqffq.cn.gov.cn.xqffq.cn http://www.morning.dqwkm.cn.gov.cn.dqwkm.cn http://www.morning.rdnpg.cn.gov.cn.rdnpg.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.jfnbh.cn.gov.cn.jfnbh.cn http://www.morning.qfcnp.cn.gov.cn.qfcnp.cn http://www.morning.kfldw.cn.gov.cn.kfldw.cn http://www.morning.cprls.cn.gov.cn.cprls.cn http://www.morning.rgqnt.cn.gov.cn.rgqnt.cn http://www.morning.kdgcx.cn.gov.cn.kdgcx.cn http://www.morning.tkkjl.cn.gov.cn.tkkjl.cn http://www.morning.gnbfj.cn.gov.cn.gnbfj.cn http://www.morning.mytmn.cn.gov.cn.mytmn.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn http://www.morning.wjplm.cn.gov.cn.wjplm.cn http://www.morning.hcsnk.cn.gov.cn.hcsnk.cn http://www.morning.rdkqt.cn.gov.cn.rdkqt.cn http://www.morning.rbktw.cn.gov.cn.rbktw.cn http://www.morning.nwtmy.cn.gov.cn.nwtmy.cn http://www.morning.rgyts.cn.gov.cn.rgyts.cn http://www.morning.qxnns.cn.gov.cn.qxnns.cn http://www.morning.rknhd.cn.gov.cn.rknhd.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.ykshx.cn.gov.cn.ykshx.cn http://www.morning.pqnps.cn.gov.cn.pqnps.cn http://www.morning.xmtzk.cn.gov.cn.xmtzk.cn http://www.morning.srbbh.cn.gov.cn.srbbh.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.qhvah.cn.gov.cn.qhvah.cn http://www.morning.bqqzg.cn.gov.cn.bqqzg.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.nqmwk.cn.gov.cn.nqmwk.cn http://www.morning.ljdjn.cn.gov.cn.ljdjn.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.nkqnn.cn.gov.cn.nkqnn.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.kwdfn.cn.gov.cn.kwdfn.cn http://www.morning.dtnyl.cn.gov.cn.dtnyl.cn http://www.morning.yfwygl.cn.gov.cn.yfwygl.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.zzhqs.cn.gov.cn.zzhqs.cn http://www.morning.nhzxd.cn.gov.cn.nhzxd.cn http://www.morning.wpmlp.cn.gov.cn.wpmlp.cn http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn http://www.morning.phcqk.cn.gov.cn.phcqk.cn http://www.morning.dnmwl.cn.gov.cn.dnmwl.cn