查询多列得到map与查询得到po对象
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
public List<Map<String, Object>> queryMatInfo(Long customer_id, List<String> matCodes) { try { Map<String, Object> params = new HashMap<String, Object>(); String sql = "select mat_id, mat_code from wms_base_material where customer_id = :customer_id and mat_code in (:matCodes)"; params.put("customer_id", customer_id); params.put("matCodes", matCodes); List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, params); return list; } catch (Exception e) { log.error(e); return new ArrayList<Map<String, Object>>(); } } List<Map<String, Object>> whList = warehouseDao.queryWhList(header.getEx_wh_code()); Map<String, Object> map = whList.get(0); wh_id = (Long)map.get("wh_id"); public List<RivCheckL> queryByExpressOrderNo(String expressOrderNo) { String sql = " select * from riv_check_l chl right join riv_pack_case_l pcl on chl.CHL_PCL_ID = pcl.PCL_ID" + " where pcl.PCL_EXPRESS_ORDER_NO = :expressOrderNo"; MapSqlParameterSource map = new MapSqlParameterSource(); map.addValue("expressOrderNo", expressOrderNo); List<RivCheckL> result = jdbcTemplate.query(sql, map, new BeanPropertyRowMapper<RivCheckL>(RivCheckL.class)); return result; }
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
List<QuantQueryForQMDTO> ls = jdbcTemplate.query(sql, params, new RowMapper<QuantQueryForQMDTO>() { @Override public QuantQueryForQMDTO mapRow(ResultSet rs, int rowNum) throws SQLException { QuantQueryForQMDTO dto = new QuantQueryForQMDTO(); dto.setOrgCode(rs.getString("org_code")); dto.setOwnCode(rs.getString("own_code")); dto.setMatCode(rs.getString("mat_code")); return dto; } });
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
public List<PcmlRecord> queryPcmlRecordLs(Integer onhId, Integer pclId, final PcmlInputUIInfoVO infoVO) { final List<PcmlRecord> pcmlRecords = new ArrayList<PcmlRecord>(); List<Object> params = new ArrayList<Object>(); StringBuilder sb = new StringBuilder(" select pcml.pcml_id, pcml.pcml_row_no, pcml.pcml_pct_id, pcml.pcml_qty, pct.pct_code, pct.pct_name "); sb.append(" from "); sb.append(" riv_pack_case_material_l pcml left join riv_pack_case_type pct on pct.pct_id = pcml.pcml_pct_id "); sb.append(" where "); sb.append(" pcml.pcml_onh_id = ? "); params.add(onhId); sb.append(" and pcml.pcml_pcl_id = ? "); params.add(pclId); this.jdbcTemplate.getJdbcOperations().query(sb.toString(), params.toArray(), new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { PcmlRecord record = infoVO.new PcmlRecord(); record.setPcmlId(SqlUtils.getIntValue(rs, "pcml_id")); record.setPcmlPctId(SqlUtils.getIntValue(rs, "pcml_pct_id")); record.setPcmlQty(SqlUtils.getIntValue(rs, "pcml_qty")); record.setPcmlRowNo(SqlUtils.getIntValue(rs, "pcml_row_no")); record.setPctCode(rs.getString("pct_code")); record.setPctName(rs.getString("pct_name")); pcmlRecords.add(record); } }); return pcmlRecords; }