1.使用JdbcTemplate操作数据
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
@Autowired
private JdbcTemplate jdbcTemplate;
public BsVisitApplyInfo getVisitApplyInfoByCode(String code) {
BsVisitApplyInfo bsVisitApplyInfo = null;
try {
int updatestrt = jdbcTemplate.update("UPDATE bs_visit_apply_info SET state = 9 WHERE meeting_park in (1,2,3) and verification_code = ?", code);
Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap("select * from bs_visit_apply_info where meeting_park = '1' and verification_code = ?", code);
bsVisitApplyInfo = MappingUtil.mapToObject(stringObjectMap, BsVisitApplyInfo.class)
使用JdbcTemplate,用sql语句在业务层直接操作数据库以及mapToObject将map转成object
于 2022-11-23 14:24:12 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)