1--实体类用Object接收
2.
@Controller
@RequestMapping(value = "/dev.do", produces = "application/json;charset=UTF-8")
public class DevController {
@Value("${photoPath}")
private String photoPath;
@Autowired
private HhDriverTableService hhDriverTableService;
@Autowired
private HhBmdService hhBMDService;
/*
* 闸机认证
*/
@RequestMapping(params = "zjrz")
@ResponseBody
public String zjrz(HttpServletRequest request) throws JSONException {
JSONObject result = new JSONObject();
try {
//接收参数
String sfzmhm = request.getParameter("id");
// sfzmhm = "632124199304091711";
String photo = request.getParameter("ph");
//将base64的photo转成图片保存在photoPath路径下
//先判断photoPath这个文件夹是否存在
File file = new File(photoPath);
if (!file.exists() && !file.isDirectory()) {
file.mkdir();
}
String name = UUID.randomUUID().toString();
photoPath= photoPath +name + ".jpg";
ImageBase64.generateImage(photo, photoPath);
//根据传过来的sfzmhm和当前日期去查询
List<HhDriverTable> driverTableList = hhDriverTableService.query(sfzmhm);
if(driverTableList.size()>0) {
HhDriverTable driverTable = driverTableList.get(0);
//更新门禁照片和testno
byte[] buffer = null;
File file2 = new File(photoPath);
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1){
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
driverTable.setMjphoto(buffer);
hhDriverTableService.update(driverTable);
result.put("code", "1");
result.put("msg", "考生报到成功!");
}else{
List<HhBmd> bmdList = hhBMDService.findBySfzmhm(sfzmhm);
if (bmdList.size()!=0) {//说明根据身份证号码找到了
result.put("code", "1");
result.put("msg", "认证成功!");
}else{
result.put("code", "0");
result.put("msg", "认证失败");
}
}
} catch (Exception e) {
result.put("code", "0");
result.put("msg", "认证失败!服务异常");
e.printStackTrace();
}
return result.toString();
}
}
mapper:
<update id="update" parameterType="com.hld.common.entity.HhDriverTable">
update driver_table
<trim prefix="set" suffixOverrides=",">
<if test="mjphoto != null and mjphoto != ''">
mjphoto=#{mjphoto},
</if>
testno= 'A' ||to_char(systimestamp,'yymmddhh24missff4')
</trim>
where lsh=#{lsh}
</update>