<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-generator -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/community
username: root
password: 123456
mybatis:
mapper-locations: classpath:mappers/*xml
type-aliases-package: com.zjw.swager.mybatis.entity
public class Building {
//TypeId是指定这个属性为id,写上这个才可以通过操作数据库中的id属性,否则类似selectById会失效
//并在后面追加类型,此处写的是自动类型
@TableId(type = IdType.AUTO)
private long id;
private String numbers;
private String uints;
private String remarks;
}
@Mapper
public interface BuildingMapper extends BaseMapper<Building> {
}
//需要继承BaseMapper
@SpringBootApplication
//扫描Mapper包下的Mapper接口
@MapperScan("com.zjw.mapper")
public class Springboottest01Application {
public static void main(String[] args) {
SpringApplication.run(Springboottest01Application.class, args);
}
}
@SpringBootTest
public class demo1 {
@Autowired
private BuildingMapper buildingMapper;
@Test
public void test01(){
Building building = buildingMapper.selectById(1);
System.out.println("building = " + building);
}
}
输出结果:
building = Building{id=1, numbers='21栋', uints='1单元', remarks='无'}
测试成功!
// 条件查询
QueryWrapper<Building> queryWrapper = new QueryWrapper<>();
// eq 参数1 给的是表的字段 参2 值
// queryWrapper.eq("sid",4);
// queryWrapper.eq("sage",40);
// queryWrapper 支持链式编程
queryWrapper.eq("sid", 4)
.eq("sage", 40);
// 条件包装类 会自动完成 sql的条件 拼接
// SELECT sid,s_name,sage,ssex,sphone FROM t_student WHERE (sid = ? AND sage = ?)
Building building = buildingMapper.selectOne(queryWrapper);
System.out.println("building = " + building);
复杂的查询条件时使用QueryWrapper条件构造器
01 添加mybatis-plus的依赖
02 配置数据库连接要素
03 写自己的mapper 继承 mp 的BaseMapper \ 要给泛型
04 需要在启动类中扫描mapper包
新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
因此需要添加MybatisPlusConfig配置类进行设置
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
// 拦截器添加分页插件
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return mybatisPlusInterceptor;
}
}
@Test
public void test02(){
QueryWrapper<Building> qr = new QueryWrapper<>();
qr.lt("id",100);
IPage<Building> page1 = new Page<>(1,4);
IPage<Building> page = buildingMapper.selectPage(page1, qr);
System.out.println("page = " + page.getRecords());
}
输出结果:
page = [Building{id=1, numbers='21栋', uints='1单元', remarks='无'}, Building{id=7, numbers='17栋', uints='2单元', remar。。。。。。
测试成功!
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-generator -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
这里的swagger版本建议用低一些的版本,高版本有兼容性问题!
Failed to start bean ‘documentationPluginsBootstrapper’ 把springboot 版本改成2.6.0 以下版本就可以
若有版本问题:
将依赖改成依赖集合
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
原先的Swagger的两个依赖不再需要
同时配置中的@EnableSwagger2也不再需要加上,以下为可选项
//@EnableSwagger2
@EnableOpenApi//可以不写
swagger需要配置类设置API文档信息
//1. 配置类
@Configuration
//2. 开启swagger支持
//@EnableSwagger2
@EnableOpenApi//swagger3.0依赖 可以不写
public class SwaggerApp {
/**
* 3、自动创建Docket文档摘要对象
*/
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2) // 选择swagger的版本,这里若选的3.0则要用OAS_30
// 配置文档信息:swagger文档的标题、版本、描述
.apiInfo(this.apiInfo())
.select()
// 配置要生成swagger文档的扫描的目录包
.apis(RequestHandlerSelectors.basePackage("com.woniu.web"))
// 对指定路径下的任意类生成文档
.paths(PathSelectors.any())
// 创建对象
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
// 指定文档标题 (在swagger页面会显示)
.title("SpringBoot中使用Swagger构建接口文件")
// 指定文档的版本
.version("1.0")
// 文档描述
.description("API描述").build();
}
}
//实体类上的注解
@ApiModel(description = "建筑类实体")
public class Building {
//TypeId是指定这个属性为id,写上这个才可以通过操作数据库中的id属性,否则类似selectById会失效
//并在后面追加类型,此处写的是自动类型
@TableId(type = IdType.AUTO)
//实体类中属性的注解
@ApiModelProperty("主键id")
private long id;
@ApiModelProperty("楼栋号")
private String numbers;
@ApiModelProperty("单元号")
private String uints;
@ApiModelProperty("备注")
private String remarks;
@Mapper
public interface BuildingMapper extends BaseMapper<Building> {
}
需要继承BaseMapper
public interface BuildingService extends IService<Building> {
}
需要继承IService
@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements BuildingService {
}
在实现BuildingService的同时,还要继承ServiceImpl<BuildingMapper ,Building>
@RestController//rest风格注解,替代@Controller和@ResponseBody
@RequestMapping("/building") 设置访问路径
@Api(tags = "楼栋管理")//swagger注解,解释controller的功能
public class BuildingController {
@Autowired//自动注入
private BuildingService buildingService;
@GetMapping
public void selectAllBuilding(){
List<Building> list = buildingService.list();
System.out.println("list = " + list);
}
}
swagger3.0访问路径:http://localhost:8080/swagger-ui/
swagger2访问路径:http://localhost:8080/swagger-ui.html
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
当前包未传递依赖 MP 包,需要自己引入!
public static void main(String[] args) {
FastAutoGenerator.create(
"jdbc:mysql://localhost:3306/spring_db",
"root",
"root")
// 全局配置
.globalConfig(builder -> {
builder.author("yellow Docter") // 设置作者
.enableSwagger() // 开启 swagger 模式
.outputDir("C:\\java_lesson\\pro\\springboot_auto\\src\\main\\java"); // 指定输出目录
})
// 包配置
.packageConfig(builder -> {
builder.parent("com.wn") // 设置父包名
.controller("controller") //controller
.service("service") //service
.serviceImpl("service.impl")
.mapper("mapper")
.xml("mapper")
.entity("entity");
})
//表的配置
.strategyConfig(builder -> {
builder.addInclude("user"); // 设置需要生成的表名
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
System.out.println("成功了...");
}
配置好生成代码类后直接运行类中主方法
即可生成
注意设置包名及路径
我在下面定义了api端点:paramsdorequires:ids,type:Array,desc:'Arrayofgroupids'end我无法从Swagger生成的UI传递数组。如果我输入[1,2,3,4]或ids%5b%5d=1&ids%5b%5d=2&ids%5b%5d=3然后两者都无效.如果我使用数组调用spec中的api,它就可以工作。我的客户想尝试Swagger的整个api,所以我想要一个适用于SwaggerUI的解决方案。 最佳答案 我对所有情况的解决方案:paramsdorequires:ids,type:Arra
如果您希望在Spring中启用定时任务功能,则需要在主类上添加 @EnableScheduling 注解。这样Spring才会扫描 @Scheduled 注解并执行定时任务。在大多数情况下,只需要在主类上添加 @EnableScheduling 注解即可,不需要在Service层或其他类中再次添加。以下是一个示例,演示如何在SpringBoot中启用定时任务功能:@SpringBootApplication@EnableSchedulingpublicclassApplication{publicstaticvoidmain(String[]args){SpringApplication.ru
软件特点部署后能通过浏览器查看线上日志。支持Linux、Windows服务器。采用随机读取的方式,支持大文件的读取。支持实时打印新增的日志(类终端)。支持日志搜索。使用手册基本页面配置路径配置日志所在的目录,配置后按回车键生效,下拉框选择日志名称。选择日志后点击生效,即可加载日志。windows路径E:\java\project\log-view\logslinux路径/usr/local/XX历史模式历史模式下,不会读取新增的日志。针对历史文件可以分页读取,配置分页大小、跳转。历史模式下,支持根据关键词搜索。目前搜索引擎使用的是jdk自带类库,搜索速度相对较低,优点是比较简单。2G日志全文搜
1.依赖导入org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-validation2.validation常用注解@Null被注释的元素必须为null@NotNull被注释的元素不能为null,可以为空字符串@AssertTrue被注释的元素必须为true@AssertFalse被注释的元素必须为false@Min(value)被注释的元素必须是一个数字,其值必须大于等于指定的最小值@Max(value)被注释的元素必须是一个数字,其值必须小于等于指定的最大值@D
我正在尝试找到一种更好的方法将IRB与我的常规ruby开发集成。目前我很少在我的代码中使用IRB。我只用它来验证语法或尝试一些小的东西。我知道我可以将我自己的代码加载到ruby中作为一个require'mycode'但这通常不符合我的编程风格。有时我要检查的变量超出范围或在循环内。有没有一种简单的方法可以启动我的脚本并在IRB内的某个点卡住?我想我正在寻找一种更简单的方法来调试我的ruby代码而不破坏我的F5(编译)键。也许有经验的ruby开发者可以和我分享一个更精简的开发方法。 最佳答案 安装ruby-debugg
我开始了一个小型网络项目并使用Drupal来构建它。到目前为止,还不错:您可以快速建立一个不错的面向CMS的网站,通过模块添加社交功能,并且您有一个广泛的API可以在一个架构良好的平台中进行自定义。现在问题来了:网站的增长超出了最初的计划,我发现自己正处于认真开始为它编写代码的境地。由于Drupal项目,我对PHP有了新的认识,但我想用Ruby来做。我会感觉更舒服,以后维护起来更容易,我可以在其他Ruby/Rails应用程序中重用它。随着时间的推移,我想我会用Ruby重写Drupal中的现有部分。基于此,问题是:是否有人将两者(成功或失败的故事)结合起来?这是一个相当大的决定,但我在G
Iparking停车收费管理系统-可商用介绍Iparking是一款基于springBoot的停车收费管理系统,支持封闭车场和路边车场,支持微信支付宝多种支付渠道,支持多种硬件,涵盖了停车场管理系统的所有基础功能。技术栈Springboot,MybatisPlus,Beetl,Mysql,Redis,RabbitMQ,UniApp功能云端功能序号模块功能描述1系统管理菜单管理配置系统菜单2系统管理组织管理管理组织机构3系统管理角色管理配置系统角色,包含数据权限和功能权限配置4系统管理用户管理管理后台用户5系统管理租户管理多租户管理6系统管理公众号配置租户公众号配置7系统管理操作日志审计日志8系统
一、Elasticsearch简介实际业务场景中,多端的查询功能都有很大的优化空间。常见的处理方式有:建索引、建物化视图简化查询逻辑、DB层之上建立缓存、分页…然而随着业务数据量的不断增多,总有那么一张表或一个业务,是无法通过常规的处理方式来缩短查询时间的。在查询功能优化上,作为开发人员应该站在公司的角度,本着优化客户体验的目的去寻找解决方案。本人有幸做过Tomcat整合solr,今天一起研究一下当前比较火热的Elasticsearch搜索引擎。Elasticsearch是一个非常强大的搜索引擎。它目前被广泛地使用于各个IT公司。Elasticsearch是由Elastic公司创建。它的代码位
目录MyBatisPlusMP特点MP框架结构MP使用准备导入依赖springboot整合mybatisplus配置文件定义好实体类User后编辑mapper接口@Mapper与@MapperScan("包名")区别MP基本操作新增操作删除操作通过id删除用户通过map作为条件删除通过多个id实现删除更新用户通过id进行用户更新查询用户 根据id查询用户根据多个id查询用户根据map集合作为条件查询用户通用Service接口一些操作 查询总记录数批量添加数据MP常用注解雪花算法前言垂直分表水平分表条件构造器继承结构使用条件构造器实现查询操作查询所有用户根据构造器查询主键字段集合根据条件构造器查
场景在SpringBoot项目中需要对接三方系统,对接协议是TCP,需实现一个TCP客户端接收服务端发送的数据并按照16进制进行解析数据,然后对数据进行过滤,将指定类型的数据通过mybatis存储进mysql数据库中。并且当tcp服务端断连时,tcp客户端能定时检测并发起重连。全流程效果 注:博客:霸道流氓气质的博客_CSDN博客-C#,架构之路,SpringBoot领域博主实现1、SpringBoot+Netty实现TCP客户端本篇参考如下博客,在如下博客基础上进行修改Springboot+Netty搭建基于TCP协议的客户端(二):https://www.cnblogs.com/haolb