Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
aa98675a
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
aa98675a
编写于
2月 20, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:在sql中使用or
上级
f17e2bb1
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
78 addition
and
3 deletion
+78
-3
src/main/java/com/kwan/springbootkwan/controller/UserController.java
...va/com/kwan/springbootkwan/controller/UserController.java
+9
-3
src/main/java/com/kwan/springbootkwan/entity/query/QueryInfo.java
.../java/com/kwan/springbootkwan/entity/query/QueryInfo.java
+13
-0
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
+17
-0
src/main/java/com/kwan/springbootkwan/service/IUserService.java
...in/java/com/kwan/springbootkwan/service/IUserService.java
+7
-0
src/main/java/com/kwan/springbootkwan/service/impl/UserServiceImpl.java
...com/kwan/springbootkwan/service/impl/UserServiceImpl.java
+11
-0
src/main/resources/mapper/UserMapper.xml
src/main/resources/mapper/UserMapper.xml
+21
-0
未找到文件。
src/main/java/com/kwan/springbootkwan/controller/UserController.java
浏览文件 @
aa98675a
...
...
@@ -6,15 +6,12 @@ import com.kwan.springbootkwan.service.IUserService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -67,4 +64,13 @@ public class UserController {
public
User
getUserByName
(
@RequestParam
String
sex
)
{
return
userService
.
getUserByName
(
sex
);
}
@ApiOperation
(
value
=
"or拼接"
,
notes
=
"or拼接"
)
@RequestMapping
(
value
=
"/getUserByOr"
,
method
=
RequestMethod
.
GET
)
public
List
<
User
>
getUserByOr
()
{
return
userService
.
getUserByOr
();
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/entity/query/QueryInfo.java
0 → 100644
浏览文件 @
aa98675a
package
com.kwan.springbootkwan.entity.query
;
import
lombok.Data
;
@Data
public
class
QueryInfo
{
private
String
invQtyA
;
private
String
invQtyB
;
private
String
invQtyC
;
private
String
invQtyD
;
}
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
浏览文件 @
aa98675a
...
...
@@ -3,6 +3,9 @@ package com.kwan.springbootkwan.mapper;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.kwan.springbootkwan.entity.User
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
...
...
@@ -15,6 +18,20 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
/**
* 通过性别获取user
*
* @param sex
* @return
*/
User
getUserByName
(
String
sex
);
/**
* 通过id获取user
*
* @param invFlag
* @return
*/
List
<
User
>
getUserByOr
(
@Param
(
"invFlag"
)
List
<
Integer
>
invFlag
);
}
src/main/java/com/kwan/springbootkwan/service/IUserService.java
浏览文件 @
aa98675a
...
...
@@ -37,4 +37,11 @@ public interface IUserService extends IService<User> {
*/
User
saveUser
(
User
user
);
/**
* 使用or拼接数据
*
* @return
*/
List
<
User
>
getUserByOr
();
}
src/main/java/com/kwan/springbootkwan/service/impl/UserServiceImpl.java
浏览文件 @
aa98675a
...
...
@@ -11,6 +11,7 @@ import io.seata.spring.annotation.GlobalTransactional;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
...
...
@@ -53,4 +54,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
personService
.
savePerson
(
person
);
return
user
;
}
@Override
public
List
<
User
>
getUserByOr
()
{
List
<
Integer
>
invFlag
=
new
ArrayList
<>();
invFlag
.
add
(
1
);
invFlag
.
add
(
2
);
invFlag
.
add
(
3
);
invFlag
.
add
(
4
);
return
userMapper
.
getUserByOr
(
invFlag
);
}
}
\ No newline at end of file
src/main/resources/mapper/UserMapper.xml
浏览文件 @
aa98675a
...
...
@@ -14,4 +14,25 @@
FROM user
WHERE sex = #{sex}
</select>
<select
id=
"getUserByOr"
resultType=
"com.kwan.springbootkwan.entity.User"
>
SELECT *
FROM user
WHERE 1 = 1
<if
test=
"invFlag != null and invFlag.size>0"
>
<foreach
collection=
"invFlag"
item=
"flag"
open=
"AND ("
close=
")"
separator=
"or"
>
<if
test=
"flag==1"
>
id
<
= 1
</if>
<if
test=
"flag==2"
>
id
>
= 2 and id
<
4
</if>
<if
test=
"flag==3"
>
id
>
= 5 and id
<
6
</if>
<if
test=
"flag==4"
>
id
>
= 8 and id
<
9
</if>
</foreach>
</if>
</select>
</mapper>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录