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

大连h5建站网站优化的方法

大连h5建站,网站优化的方法,分销网站建立,opencart做网站视频1、MyBatis-Plus概述 MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。 【技术储备】 拥有 Java 开发环境以及相应 IDE…

1、MyBatis-Plus概述

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

【技术储备】

拥有 Java 开发环境以及相应 IDE

熟悉 Spring Boot

熟悉 Maven

【特征】

为简化开发而生

1、只做增强不做改变,引入它不会对现有工程产生影响,如丝般顺滑。

2、效率至上:只需简单配置,即可快速进行单表 CRUD 操作,从而节省大量时间。

3、丰富功能:代码生成、自动分页、逻辑删除、自动填充等功能一应俱全。

2、数据库支持

任何能使用 MyBatis 进行 CRUD, 并且支持标准 SQL 的数据库,具体支持情况如下,如果不在下列表查看分页部分教程 PR 您的支持。

MySQL,Oracle,DB2,H2,HSQL,SQLite,PostgreSQL,SQLServer,Phoenix,Gauss ,ClickHouse,Sybase,OceanBase,Firebird,Cubrid,Goldilocks,csiidb,informix,TDengine,redshift

达梦数据库,虚谷数据库,人大金仓数据库,南大通用(华库)数据库,南大通用数据库,神通数据库,瀚高数据库,优炫数据库,星瑞格数据库

3、快速上手案例

版本信息:springboot2.7.14+mysql5.1.42+mybatis-plus3.5.3.2

【工程结构】

3.1、创建springboot工程被导入相关依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.2</version>
</dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.42</version>
</dependency>
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional>
</dependency>

3.2、配置数据库相关信息

log-impl控制台打印出mybatis执行时的具体sql、查询条件、返回值等

map-underscore-to-camel-casemybatisplus在查询数据库的时候回默认的开启数据库下划线驼峰命名转化,我们需要关闭。

spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatisplususername: rootpassword: 123456mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplmap-underscore-to-camel-case: false# 如果是放在src/main/java目录下 classpath:/com/*/*/mapper/*Mapper.xml# 如果是放在resource目录 classpath:/mapper/**.xml#mapper-locations: classpath:/mapper/**.xml

3.3、创建数据库和表信息

CREATE DATABASE mybatisplus;
USE mybatisplus;
CREATE TABLE student(stu_id VARCHAR(50),stu_name VARCHAR(30),stu_sex VARCHAR(2),stu_age VARCHAR(4),stu_addr VARCHAR(50),stu_pwd VARCHAR(50)
)DEFAULT CHARSET=utf8;
INSERT INTO student VALUES('1001','晓春','男','33','安徽合肥','1001');
INSERT INTO student VALUES('1002','陈平安','男','18','安徽合肥','1002');

3.4、创建bean对象

@TableName("student"):定义映射表信息

@TableId("stu_id"):定义数据库主键

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("student")
public class Student {@TableId("stu_id")private String stu_id;private String stu_name;private String stu_sex;private String stu_age;private String stu_addr;private String stu_pwd;
}

3.5、创建Mapper接口

public interface StudentMapper extends BaseMapper<Student> {
}

3.6、在启动类中扫描mapper接口

通过@MapperScan("com.txc.mybatisplus.mapper")注解扫描mapper接口,注意地址不能写错了。

@SpringBootApplication
@MapperScan("com.txc.mybatisplus.mapper")
public class Mybatisplusdemo1Application {public static void main(String[] args) {SpringApplication.run(Mybatisplusdemo1Application.class, args);}
}

3.7、功能1:查询所有学生信息

通过springweb创建一个测试类,查询student表中的所有学生信息

@RestController
public class StudentController {@Autowired(required = false)StudentMapper studentMapper;@RequestMapping("/testmybatisplus")@ResponseBodypublic void testMybatisPlus() {List<Student> list=studentMapper.selectList(null);//Assert.isTrue(5 == list.size(), "");list.forEach(System.out::println);}
}

3.8、功能2:模糊查询学生信息

说明1:queryWrapper.eq("stu_name","陈平安");//表示根据stu_name字段查询陈平安
       效果类似于:select * from student where stu_name=’陈平安’

说明2:queryWrapper.like("stu_addr","安徽合肥");//表示根据stu_addr模糊查询安徽合肥
       效果类似于
select * from student where stu_addr like ’%陈平安%’

两者合起来的效果是:

select * from student where stu_name=’陈平安’ and stu_addr like ’%陈平安%’;

@Controller
public class StudentController {@Autowired(required = false)StudentMapper studentMapper;//根据姓名查询学生信息@RequestMapping("/testMybatisPlusByName")@ResponseBodypublic void testMybatisPlusByName() {//QueryWrapper封装查询信息QueryWrapper<Student> queryWrapper=new QueryWrapper<>();//表示查询的时候表字段stu_name的值为陈平安queryWrapper.eq("stu_name","陈平安");//表示根据stu_addr模糊查询安徽合肥queryWrapper.like("stu_addr","安徽合肥");List<Student> list=studentMapper.selectList(queryWrapper);list.forEach(stu->{System.out.println(stu.getStu_name());});}

3.9、功能3:根据id查询学生信息

//根据id查询学生信息
@RequestMapping("/testMybatisPlusById")
@ResponseBody
public void testMybatisPlusById() {//QueryWrapper封装查询信息QueryWrapper<Student> queryWrapper=new QueryWrapper<>();//表示查询的时候表字段stu_name的值为陈平安queryWrapper.eq("stu_id","1001");Student stu=studentMapper.selectOne(queryWrapper);System.out.println(stu.toString());
}
}

3.10、功能3:添加学生信息

@Controller
public class StudentController {@Autowired(required = false)StudentMapper studentMapper;//添加学生信息@RequestMapping("/testMybatisPlusAdd")@ResponseBodypublic void testMybatisPlusAdd() {Student stu=new Student("1003","十一郎","男","34","安徽合肥","1003");studentMapper.insert(stu);System.out.println("=======数据添加成功========");}
}

3.11、功能4:修改学生信息

@Controller
public class StudentController {@Autowired(required = false)StudentMapper studentMapper;//修改学生信息@RequestMapping("/testMybatisPlusupdate")@ResponseBodypublic void testMybatisPlusupdate() {Student stu=new Student("1003","十一郎","男","34","安徽合肥","1003");studentMapper.updateById(stu);System.out.println("=======数据修改成功========");}
}

3.12、功能5:删除学生信息

@Controller
public class StudentController {@Autowired(required = false)StudentMapper studentMapper;//删除学生信息@RequestMapping("/testMybatisPlusDelete")@ResponseBodypublic void testMybatisPlusDelete() {Student stu=new Student();stu.setStu_id("1003");studentMapper.deleteById(stu);System.out.println("=======删除修改成功========");}
}

4、源码下载

源码属于vip资源,如果需要可在评论区留言,我修改成免费。

https://download.csdn.net/download/tangshiyilang/88276862

http://www.15wanjia.com/news/8152.html

相关文章:

  • 盗版网站是如何做的广州全网推广
  • dede中英文企业网站网站服务器查询
  • 大气网站图企业营销策略分析论文
  • 北京网络营销岗位数量惠州百度seo
  • 网站建设是属于b2网络营销软文范例500字
  • 成都快型网络公司排名高级seo是什么职位
  • 楚雄建网站百度新闻头条新闻
  • 石家庄网站建设联系方式淄博做网站的公司
  • 做网站怎么提取视频无广告下载百度搜索
  • 企业为什么做网站 图片自然搜索优化
  • 自己做网站必须要学哪些英文外链seo兼职
  • 夏天做那些网站能致富百度推广哪种效果好
  • 做外贸用哪些网站百度地图优化排名方法
  • 视频做网站背景百度指数搜索热度大学
  • 网站开发说明书模板电脑培训学校在哪里
  • 优秀个人网站主页优化大师如何删掉多余的学生
  • 用国外服务器做赌博网站靠谱的影视后期培训班
  • 网络建设的流程网站关键词挖掘工具爱站网
  • 山东企业网站建设报价市场监督管理局投诉电话
  • 国内好的网站设计互联网营销师报名
  • asp网站建设代码seo顾问能赚钱吗
  • 启东做网站郑州厉害的seo顾问
  • 响应式网站是做多大尺寸seo与网络推广的区别和联系
  • 北京网站备案查询西安百度推广运营公司
  • 管理咨询公司网站互联网销售包括哪些
  • 建网站难不难今天nba新闻最新消息
  • 专业的营销型网站制作百度客服中心人工电话
  • wordpress 多站点共享新冠疫情最新消息今天
  • 网页作品集星链seo管理
  • 做网站给源码吗seo链接优化建议