select * from zdyjkzbjl where jsbh='330400111' and TO_CHAR( pbrq , 'yyyy-mm-dd')='2023-05-23' and bc ='1' and TO_CHAR( jbsj , 'yyyy-mm-dd hh24:MI')<>'2023-05-23 07:50' and TO_CHAR( jiaobsj , 'yyyy-mm-dd hh24:MI')<>'2023-05-23 19:50' and TO_CHAR( now() , 'yyyy-mm-dd hh24:MI:SS') BETWEEN '2023-05-23 07:50:00' and '2023-05-23 17:00:00'; --一班次 23/07- 23/17 提醒时间 select * from zdyjkzbjl where jsbh='330400111' and TO_CHAR( pbrq , 'yyyy-mm-dd')='2023-05-23' and bc ='2' and TO_CHAR( jbsj , 'yyyy-mm-dd hh24:MI')='2023-05-23 19:50' and TO_CHAR( jiaobsj , 'yyyy-mm-dd hh24:MI')='2023-05-24 01:50' and TO_CHAR( now(), 'yyyy-mm-dd hh24:MI:SS') BETWEEN '2023-05-23 17:00:00' and '2023-05-24 01:30:00'; --二班次 23/17 -24/01 提醒时间 select * from zdyjkzbjl where jsbh='330400111' and TO_CHAR( pbrq , 'yyyy-mm-dd')='2023-05-23' and bc='3' and TO_CHAR( jbsj , 'yyyy-mm-dd hh24:MI')<>'2023-05-24 01:50' and TO_CHAR( jiaobsj , 'yyyy-mm-dd hh24:MI')<>'2023-05-24 07:50' and TO_CHAR( now() , 'yyyy-mm-dd hh24:MI:SS') BETWEEN '2023-05-24 01:30:00' and '2023-05-24 07:50:00'; 如何根据时间来分别调用其中的一个sql ,使用java 和mybatis 参数传入对应的时间和jsbh
时间: 2023-08-12 13:07:42 浏览: 52
你可以使用Java中的SimpleDateFormat类来解析和格式化日期时间,然后将其作为参数传递给MyBatis的Mapper方法。
比如,你可以定义一个Mapper接口如下:
```java
public interface ZdyjkzbjlMapper {
List<Zdyjkzbjl> findFirstShift(@Param("jsbh") String jsbh, @Param("date") String date);
List<Zdyjkzbjl> findSecondShift(@Param("jsbh") String jsbh, @Param("date") String date);
List<Zdyjkzbjl> findThirdShift(@Param("jsbh") String jsbh, @Param("date") String date);
}
```
然后,你可以在Mapper XML文件中编写对应的SQL语句:
```xml
<select id="findFirstShift" resultType="Zdyjkzbjl">
select * from zdyjkzbjl
where jsbh = #{jsbh}
and TO_CHAR(pbrq, 'yyyy-mm-dd') = #{date}
and bc = '1'
and TO_CHAR(jbsj, 'yyyy-mm-dd hh24:MI') <> '2023-05-23 07:50'
and TO_CHAR(jiaobsj, 'yyyy-mm-dd hh24:MI') <> '2023-05-23 19:50'
and TO_CHAR(now(), 'yyyy-mm-dd hh24:MI:SS') BETWEEN '2023-05-23 07:50:00' and '2023-05-23 17:00:00';
</select>
<select id="findSecondShift" resultType="Zdyjkzbjl">
select * from zdyjkzbjl
where jsbh = #{jsbh}
and TO_CHAR(pbrq, 'yyyy-mm-dd') = #{date}
and bc = '2'
and TO_CHAR(jbsj, 'yyyy-mm-dd hh24:MI') = '2023-05-23 19:50'
and TO_CHAR(jiaobsj, 'yyyy-mm-dd hh24:MI') = '2023-05-24 01:50'
and TO_CHAR(now(), 'yyyy-mm-dd hh24:MI:SS') BETWEEN '2023-05-23 17:00:00' and '2023-05-24 01:30:00';
</select>
<select id="findThirdShift" resultType="Zdyjkzbjl">
select * from zdyjkzbjl
where jsbh = #{jsbh}
and TO_CHAR(pbrq, 'yyyy-mm-dd') = #{date}
and bc = '3'
and TO_CHAR(jbsj, 'yyyy-mm-dd hh24:MI') <> '2023-05-24 01:50'
and TO_CHAR(jiaobsj, 'yyyy-mm-dd hh24:MI') <> '2023-05-24 07:50'
and TO_CHAR(now(), 'yyyy-mm-dd hh24:MI:SS') BETWEEN '2023-05-24 01:30:00' and '2023-05-24 07:50:00';
</select>
```
最后,你可以在Java中调用Mapper方法,传入相应的参数:
```java
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = "2023-05-23";
String jsbh = "330400111";
List<Zdyjkzbjl> firstShiftList = zdyjkzbjlMapper.findFirstShift(jsbh, dateStr);
List<Zdyjkzbjl> secondShiftList = zdyjkzbjlMapper.findSecondShift(jsbh, dateStr);
List<Zdyjkzbjl> thirdShiftList = zdyjkzbjlMapper.findThirdShift(jsbh, dateStr);
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)