写一个正则表达式匹配类似”3.4.2“的数字
时间: 2023-06-15 17:03:33 浏览: 105
可以使用以下正则表达式匹配类似 “3.4.2” 的数字:
```
^\d+(\.\d+){2}$
```
解释:
- `^`:匹配字符串的开头
- `\d+`:匹配一个或多个数字
- `(\.\d+){2}`:匹配含有两个小数点及一个或多个数字的子串
- `\.`:匹配小数点
- `\d+`:匹配一个或多个数字
- `$`:匹配字符串的结尾
因此,该正则表达式可以匹配类似 “3.4.2” 的数字。
相关问题
用springboot mybatisplus 写一个获取user表列表信息
好的,以下是一个使用Spring Boot和MyBatis Plus获取user表列表信息的示例代码:
首先,需要在maven中添加MyBatis Plus和MySQL连接器的依赖:
```xml
<dependencies>
<!-- Spring Boot Starter Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MyBatis Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<!-- MySQL Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
</dependencies>
```
接着,在application.properties文件中添加数据库连接等相关配置信息:
```properties
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# MyBatis Plus 配置
mybatis-plus.mapper-locations=classpath:/mapper/**/*.xml
mybatis-plus.global-config.db-config.id-type=auto
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
```
然后,创建一个User实体类,对应user表的结构:
```java
public class User {
private Long id;
private String name;
private Integer age;
private String email;
// getter 和 setter 方法省略
}
```
接下来,创建一个UserMapper接口,继承BaseMapper接口,并定义一个getUserList方法,用于查询user表的所有记录:
```java
@Mapper
public interface UserMapper extends BaseMapper<User> {
List<User> getUserList();
}
```
最后,在UserService中调用UserMapper的getUserList方法,获取user表的所有记录:
```java
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
public List<User> getUserList() {
return userMapper.getUserList();
}
}
```
这样,就可以成功获取到user表的所有记录了。
用mybatis-plus-join写一个迷糊查询
首先,需要在pom.xml中添加mybatis-plus和数据库驱动的依赖:
```xml
<dependencies>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
</dependencies>
```
接着,创建实体类和mapper接口,以User和Order为例:
User实体类:
```java
@Data
public class User {
private Long id;
private String name;
private Integer age;
}
```
UserMapper接口:
```java
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
```
Order实体类:
```java
@Data
public class Order {
private Long id;
private Long userId;
private String orderNo;
private Date createTime;
}
```
OrderMapper接口:
```java
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
}
```
然后,在UserService中使用mybatis-plus-join实现迷糊查询:
```java
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private OrderMapper orderMapper;
public List<User> findUsersByNameLike(String name) {
QueryWrapper<User> userWrapper = new QueryWrapper<>();
userWrapper.like("name", name);
return userMapper.selectList(userWrapper);
}
public List<User> findUsersByOrderCreateTimeBetween(Date start, Date end) {
QueryWrapper<User> userWrapper = new QueryWrapper<>();
userWrapper.inSql("id", "select user_id from `order` where create_time between #{start} and #{end}");
return userMapper.selectList(userWrapper);
}
public List<User> findUsersByOrderNoLike(String orderNo) {
QueryWrapper<User> userWrapper = new QueryWrapper<>();
userWrapper.inSql("id", "select user_id from `order` where order_no like concat('%', #{orderNo}, '%')");
return userMapper.selectList(userWrapper);
}
public List<User> findUsersByOrderNoLikeAndAgeBetween(String orderNo, Integer startAge, Integer endAge) {
QueryWrapper<User> userWrapper = new QueryWrapper<>();
userWrapper.inSql("id", "select user_id from `order` where order_no like concat('%', #{orderNo}, '%')")
.between("age", startAge, endAge);
return userMapper.selectList(userWrapper);
}
}
```
其中,findUsersByNameLike方法实现了根据用户姓名模糊查询的功能;findUsersByOrderCreateTimeBetween方法实现了查询在某个时间范围内下单的用户列表;findUsersByOrderNoLike方法实现了根据订单号模糊查询的功能;findUsersByOrderNoLikeAndAgeBetween方法实现了根据订单号模糊查询,并且年龄在某个范围内的用户列表。
阅读全文