用java实现出库审批 通过审核状态判断是否通过通过就添加到出库记录 mybatis restful domain mapper interface service controller详细代码
时间: 2024-02-01 08:02:28 浏览: 90
基于springboot+activity+mybatis+activity工作流审批前后台代码(源码+数据库+页面展示)
以下是一个简单的Java实现出库审批的示例代码,包括了MyBatis、Restful、Domain、Mapper、Interface、Service和Controller:
1. Domain类
```
public class OutboundApproval {
private int id;
private String productName;
private int quantity;
private String approvalStatus;
// Getters and Setters
}
```
2. Mapper接口
```
public interface OutboundApprovalMapper {
List<OutboundApproval> getAllOutboundApprovals();
OutboundApproval getOutboundApprovalById(int id);
void addOutboundApproval(OutboundApproval outboundApproval);
void updateOutboundApproval(OutboundApproval outboundApproval);
}
```
3. Service类
```
@Service
public class OutboundApprovalService {
@Autowired
private OutboundApprovalMapper outboundApprovalMapper;
public List<OutboundApproval> getAllOutboundApprovals() {
return outboundApprovalMapper.getAllOutboundApprovals();
}
public OutboundApproval getOutboundApprovalById(int id) {
return outboundApprovalMapper.getOutboundApprovalById(id);
}
public void addOutboundApproval(OutboundApproval outboundApproval) {
outboundApprovalMapper.addOutboundApproval(outboundApproval);
}
public void updateOutboundApproval(OutboundApproval outboundApproval) {
outboundApprovalMapper.updateOutboundApproval(outboundApproval);
}
}
```
4. Controller类
```
@RestController
@RequestMapping("/outboundApproval")
public class OutboundApprovalController {
@Autowired
private OutboundApprovalService outboundApprovalService;
@GetMapping("/")
public List<OutboundApproval> getAllOutboundApprovals() {
return outboundApprovalService.getAllOutboundApprovals();
}
@GetMapping("/{id}")
public OutboundApproval getOutboundApprovalById(@PathVariable int id) {
return outboundApprovalService.getOutboundApprovalById(id);
}
@PostMapping("/")
public void addOutboundApproval(@RequestBody OutboundApproval outboundApproval) {
outboundApprovalService.addOutboundApproval(outboundApproval);
}
@PutMapping("/")
public void updateOutboundApproval(@RequestBody OutboundApproval outboundApproval) {
outboundApprovalService.updateOutboundApproval(outboundApproval);
}
}
```
5. MyBatis映射文件
```
<mapper namespace="com.example.mapper.OutboundApprovalMapper">
<select id="getAllOutboundApprovals" resultType="com.example.domain.OutboundApproval">
SELECT * FROM outbound_approval
</select>
<select id="getOutboundApprovalById" parameterType="int" resultType="com.example.domain.OutboundApproval">
SELECT * FROM outbound_approval WHERE id = #{id}
</select>
<insert id="addOutboundApproval" parameterType="com.example.domain.OutboundApproval">
INSERT INTO outbound_approval (productName, quantity, approvalStatus)
VALUES (#{productName}, #{quantity}, #{approvalStatus})
</insert>
<update id="updateOutboundApproval" parameterType="com.example.domain.OutboundApproval">
UPDATE outbound_approval
SET productName = #{productName}, quantity = #{quantity}, approvalStatus = #{approvalStatus}
WHERE id = #{id}
</update>
</mapper>
```
6. Restful API示例
- 获取所有出库审批记录:GET /outboundApproval/
- 获取指定ID的出库审批记录:GET /outboundApproval/{id}
- 添加一条出库审批记录:POST /outboundApproval/
- 更新一条出库审批记录:PUT /outboundApproval/
阅读全文