两表联查的JSON取值

来源:互联网 发布:靠网络如何挣钱 编辑:程序博客网 时间:2024/06/06 17:39

//关联对象private CameraVO camera;publicJSONObject toJSON() {     DateFormatUtildateFormatUtil =new DateFormatUtil() ;   JSONObject resultJSON = newJSONObject();      resultJSON.put("id",this.getId());      resultJSON.put("camera_id",this.getCamera_id());      resultJSON.put("camera_no",this.getCamera().getNo());      /*resultJSON.put("capture_time", this.getCapture_time());*/      resultJSON.put("capture_time",dateFormatUtil.dateTimeStr(this.getCapture_time()));      resultJSON.put("current_distinguish_num",this.getCurrent_distinguish_num());      resultJSON.put("front_distinguish_num",this.getFront_distinguish_num());      resultJSON.put("capture_num",this.getCapture_num());      resultJSON.put("current_address",this.getCurrent_address());      resultJSON.put("front_address",this.getFront_address());      resultJSON.put("description",this.getDescription());      // resultJSON.put("no", this.no);      returnresultJSON;   }<!-- 查询多条捕获信息 --><resultMap type="com.sbd.vo.CaptureInfoVO"id="captureInfo"autoMapping="true">   <idproperty="id"column="id"/>   <associationproperty="camera"javaType="com.sbd.vo.CameraVO"autoMapping="true">         <idproperty="id"column="cid"/>         <idproperty="no"column="no"/>   </association></resultMap>//两表联查时,同名字段位置靠后的必须改名,比如:第一张表的主键为id,第二张表的主键也为id,两表有关联,做查询时,第二张表的主键要起别名,否则会默认第一章标的主键   <select id="findCaptureInfo" parameterType="map" resultMap="captureInfo">      select c.*,camera.no,camera.idcid from capture_info c          left join camera on c.camera_id = camera.id;      <where>           //主键和外键模糊查询条件                <iftest="capture_time != null and capture_time != '' ">            andcapture_time like #{capture_time}           </if>                </where>   </select>


原创粉丝点击