博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
@Transient注解输出空间位置属性
阅读量:5756 次
发布时间:2019-06-18

本文共 17031 字,大约阅读时间需要 56 分钟。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bitree1/article/details/80830186

 一、@Transient注解

1.serialization会忽略掉

Java的serialization提供了一种持久化对象实例的机制。当持久化对象时,可能有一个特殊的对象数据成员,我们不想用serialization机制来保存它。

为了在一个特定对象的一个域上关闭serialization,可以在这个域前加上关键字transient

2.不跟数据库表做映射 就是表中没有这个字段

@Transient表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性.

二、使用@Transient注解输出空间位置属性POINTS Geometry属性

1.实体类

package com.trgis.trmap.gov.model;import java.io.Serializable;import java.util.Date;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;import javax.persistence.Transient;import org.hibernate.annotations.Cache;import org.hibernate.annotations.CacheConcurrencyStrategy;import org.hibernate.annotations.Type;import com.alibaba.fastjson.annotation.JSONField;import com.fasterxml.jackson.annotation.JsonFormat;import com.fasterxml.jackson.annotation.JsonIgnore;import com.trgis.trmap.gov.util.EnumUtil;import com.vividsolutions.jts.geom.Geometry;/** * 县域平台 * @author liuyan * */@Entity@Table(name = "xjpt")@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)public class PT implements Serializable{	/**	 * @Fields serialVersionUID : serialVersionUID	 */	private static final long serialVersionUID = 1L;		/**	 * id	 */	@Id	@GeneratedValue(strategy = GenerationType.AUTO)	private Long id;			/**	 * geometry 中心点	 */	@Column(name="geom")	@Type(type = "org.hibernate.spatial.GeometryType")	@JsonIgnore	//@JSONField(serialize = false)	private Geometry geom;	/**	 * geometry	 */	@Transient	@JSONField(deserialize = false)	private String points;	/**	 * 平台配色方案	 */	@Column(name="style")	private String style;			/**	 * 平台状态 关停 启动	 */	@Column(name="status")	private Integer status = EnumUtil.PTSTATUS.QD.getValue();	/**	 * 平台名称	 */	@Column(name="ptname")	private String ptname;	/**	 * 平台的访问目录 /main/zzx	 */	@Column(name="pturl")	private String pturl;	/**	 * 平台的等级  省级1   市级2  县级 3	 */	@Column(name="level")	private Integer level =1;	/**	 * 平台的父级	 */	@Column(name="parentid")	private Long parentid ;	/**	 * 创建时间		 * @return	 */	@Column(name="createTime")	@JsonFormat(pattern="yyyy-MM-dd  HH:mm:ss",timezone="GMT+8")	private Date createTime =  new Date();	public Long getId() {		return id;	}	public void setId(Long id) {		this.id = id;	}	public String getStyle() {		return style;	}	public void setStyle(String style) {		this.style = style;	}	public Date getCreateTime() {		return createTime;	}	public void setCreateTime(Date createTime) {		this.createTime = createTime;	}		public Long getParentid() {		return parentid;	}	public void setParentid(Long parentid) {		this.parentid = parentid;	}	public String  getPoints() {		return this.geom.toString();	}	public void setPoints(String points) {		this.points = this.geom.toString();	}	public Integer getStatus() {		return status;	}	public void setStatus(Integer status) {		this.status = status;	}	public String getPtname() {		return ptname;	}	public void setPtname(String ptname) {		this.ptname = ptname;	}	public String getPturl() {		return pturl;	}	public void setPturl(String pturl) {		this.pturl = pturl;	}	public Integer getLevel() {		return level;	}	public void setLevel(Integer level) {		this.level = level;	}	public Geometry getGeom() {		return geom;	}	public void setGeom(Geometry geom) {		this.geom = geom;	}	public PT() {		super();	}	@Override	public String toString() {		return "PT [id=" + id + ", geom=" + geom + ", points=" + points + ", style=" + style + ", status=" + status				+ ", ptname=" + ptname + ", pturl=" + pturl + ", level=" + level + ", parentid=" + parentid				+ ", createTime=" + createTime + "]";	}	public PT(Long id, Geometry geom, String points, String style, Integer status, String ptname, String pturl,			Integer level, Long parentid, Date createTime) {		super();		this.id = id;		this.geom = geom;		this.points = points;		this.style = style;		this.status = status;		this.ptname = ptname;		this.pturl = pturl;		this.level = level;		this.parentid = parentid;		this.createTime = createTime;	}}

points 属性作为geom字段的输出格式  但是在数据里面不存在   geom属性则忽略,仔细看points的get set 方法

2.modelvo

package com.trgis.trmap.gov.model.vo;import java.util.Date;import java.util.List;import com.trgis.trmap.gov.model.PT;import com.trgis.trmap.gov.util.EnumUtil;import com.vividsolutions.jts.geom.Geometry;/** * 县域平台vo * @author liuyan * */public class PTVO{		/**	 * id	 */	private Long id;			/**	 * geometry 中心点	 */	private Geometry geom;		private String points;	/**	 * 平台配色方案	 */	private String style;		/**	 * 平台状态 关停 启动	 */	private Integer status = EnumUtil.PTSTATUS.QD.getValue();	/**	 * 平台名称	 */	private String ptname;	/**	 * 平台的访问目录 /main/zzx	 */	private String pturl;	/**	 * 平台的等级  省级1   市级2  县级 3	 */	private Integer level =1;	/**	 * 平台的父级	 */	private Integer parentid ;	/**	 * 创建时间		 * @return	 */	private Date createTime =  new Date();		/**	 * 子集	 */		private List
child; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getStyle() { return style; } public void setStyle(String style) { this.style = style; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Integer getParentid() { return parentid; } public void setParentid(Integer parentid) { this.parentid = parentid; } public Geometry getPoints() { return geom; } public void setPoints(Geometry points) { this.geom = points; } public Integer getStatus() { return status; } public void setStatus(Integer status) { this.status = status; } public String getPtname() { return ptname; } public void setPtname(String ptname) { this.ptname = ptname; } public String getPturl() { return pturl; } public void setPturl(String pturl) { this.pturl = pturl; } public Integer getLevel() { return level; } public void setLevel(Integer level) { this.level = level; } public List
getChild() { return child; } public void setChild(List
child) { this.child = child; } public String getGeometry() { return points; } public void setGeometry(String points) { this.points = points; } @Override public String toString() { return "PTVO [id=" + id + ", geom=" + geom + ", points=" + points + ", style=" + style + ", status=" + status + ", ptname=" + ptname + ", pturl=" + pturl + ", level=" + level + ", parentid=" + parentid + ", createTime=" + createTime + ", child=" + child + "]"; } }

3.dao

package com.trgis.trmap.gov.repository;import java.util.List;import org.springframework.data.jpa.repository.JpaRepository;import org.springframework.data.jpa.repository.JpaSpecificationExecutor;import org.springframework.stereotype.Repository;import com.trgis.trmap.gov.model.PT;import com.trgis.trmap.gov.model.Points;/** * 平台数据层 * @author Administrator * */@Repositorypublic interface PTRepository extends JpaRepository
, JpaSpecificationExecutor
{ List
findByLevel(Integer level); }

4 service

package com.trgis.trmap.gov.service;import java.util.List;import com.trgis.common.page.ConditionGroup;import com.trgis.trmap.gov.model.PT;/** *要素的service 层 * @author Administrator * */public interface PTService {	//添加一个平台并返回id	public Long save(PT pt);	//根据id删除	public void delPT(Long id);	//修改信息	public void updPT(PT pt);	//根据id查询单个信息	public PT findById(Long id);	//根据id查询单个信息	public List
findByLevel(Integer level); //根据条件查询 public List
findByConditions(ConditionGroup conditionGroup);}

5.serviceimpl

package com.trgis.trmap.gov.service.impl;import java.util.List;import javax.transaction.Transactional;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.domain.Sort;import org.springframework.data.domain.Sort.Direction;import org.springframework.data.jpa.domain.Specification;import org.springframework.stereotype.Service;import com.trgis.common.page.ConditionGroup;import com.trgis.common.page.DynamicSpecficationUtil;import com.trgis.trmap.gov.model.PT;import com.trgis.trmap.gov.repository.PTRepository;import com.trgis.trmap.gov.service.PTService;/** *  * 平台的service实现类 * @author liuyan  * */@Service@Transactionalpublic class PTServiceImp implements PTService {	@Autowired	private PTRepository PTRepository;	@Override	public Long save(PT pt) {		PTRepository.saveAndFlush(pt);		Long id = pt.getId();		return id;	}	@Override	public void delPT(Long id) {		PTRepository.delete(id);	}	@Override	public void updPT(PT pt) {		PTRepository.saveAndFlush(pt);	}	@Override	public PT findById(Long id) {		return PTRepository.findOne(id);	}	@Override	public List
findByLevel(Integer level) { return PTRepository.findByLevel(level); } @Override public List
findByConditions(ConditionGroup conditionGroup) { Specification specifications = DynamicSpecficationUtil.buildSpecfication(conditionGroup); long count = PTRepository.count(specifications); if (count == 0) { return null; } Sort sort = new Sort(Direction.DESC,"id"); return PTRepository.findAll(specifications,sort); }}

6.controller

package com.trgis.address.xjpt;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.BeanUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.servlet.ModelAndView;import com.trgis.common.page.ConditionGroup;import com.trgis.common.page.Operator;import com.trgis.common.page.SearchCondition;import com.trgis.common.page.SearchRelation;import com.trgis.trmap.gov.controller.DataCorrigendaController;import com.trgis.trmap.gov.model.GovUser;import com.trgis.trmap.gov.model.PT;import com.trgis.trmap.gov.model.vo.PTVO;import com.trgis.trmap.gov.service.PTService;import com.trgis.trmap.gov.util.BeanUtil;import com.vividsolutions.jts.geom.Point;import com.vividsolutions.jts.io.ParseException;import com.vividsolutions.jts.io.WKTReader;/* * 统计服务点击量和系统登录量 */@Controller@RequestMapping("/xypt")public class XJPTController {private static final Logger logger = LoggerFactory.getLogger(DataCorrigendaController.class);@Autowiredprivate PTService ptService;/** * 县级平台页面 * @param request * @return */@RequestMapping(value = "/xjpt", method = RequestMethod.GET)public ModelAndView page(HttpServletRequest request){	ModelAndView mod= new ModelAndView();	 GovUser user = (GovUser) request.getSession().getAttribute("UserSession");     if (BeanUtil.isNotEmpty(user)) {             mod = new ModelAndView("xjpt");             //mod.setViewName("/deptser/manager_xjpt");     } else {         mod = new ModelAndView("redirect:/login");     }	return mod;}/** * 获取当前项目 * @return */@ResponseBody@RequestMapping(value = "/getRoot", method ={ RequestMethod.GET, RequestMethod.POST })public Map
index() { Map
map = new HashMap
(); PT pt = null; String id= System.getenv("SXSK_WEB_ROOT"); System.err.print("当前主系统ID:"+id); if(id!=""){ long l=Long.parseLong(id); pt = ptService.findById(l); }else { pt = ptService.findById(1l); } map.put("result", "success"); map.put("system", pt); return map;}/** * 根据id查找 * @param id * @return */@ResponseBody@RequestMapping(value = "/findByID", method = { RequestMethod.GET, RequestMethod.POST })public Map
findByID(String id) { Map
map = new HashMap
(); PT pt = null; if(id!=""){ long l=Long.parseLong(id); pt = ptService.findById(l); map.put("result", "success"); }else { map.put("result", "err"); } map.put("system", pt); return map;}/** * 保存县域平台 * @param pt 平台信息 * @param place 位置信息 * @param session * @param request * @return */@ResponseBody@RequestMapping(value = "/save",method = { RequestMethod.GET, RequestMethod.POST })public Map
save(PT pt,String place,HttpSession session,HttpServletRequest request){ WKTReader wkt = new WKTReader(); com.vividsolutions.jts.geom.Geometry geometry =null; try { geometry = wkt.read(place); } catch (ParseException e1) { e1.printStackTrace(); } Map
map = new HashMap
(); GovUser tuser =(GovUser) request.getSession().getAttribute("UserSession"); pt.setGeom((Point)geometry); pt.setPoints(place); try{ if(BeanUtil.isNotEmpty(tuser)){ pt.setCreateTime(new Date()); ptService.save(pt); logger.debug("add success....."); map.put("result", "success"); map.put("msg", "提交县域平台信息成功!"); }else{ map.put("result", "error"); map.put("msg", "用户未登录!"); } }catch(Exception e){ map.put("result", "error"); map.put("msg", "提交县域平台信息失败!"); } map.put("data",pt); return map; }/** * 修改平台状态信息 * @param id * @param status * @param request * @return */@ResponseBody@RequestMapping(value = "/updatestatus", method = { RequestMethod.GET, RequestMethod.POST })public Map
updateStatus(Long id,Integer status,HttpServletRequest request){ Map
map = new HashMap<>(); GovUser tuser =(GovUser) request.getSession().getAttribute("UserSession"); if(BeanUtil.isNotEmpty(tuser)){ try{ PT pt = ptService.findById(id); if(BeanUtil.isNotEmpty(pt)){ pt.setStatus(status); ptService.save(pt); } logger.debug("add success....."); map.put("result", "chenggong"); map.put("msg", "状态修改成功!"); map.put("data",pt); }catch(Exception e){ map.put("data",null); map.put("result", "shibai"); map.put("msg", "状态修改失败!"); } }else{ map.put("result", "error"); map.put("msg", "用户未登录!"); } return map; }/** * 删除县域平台 * @param id * @param request * @return */@ResponseBody@RequestMapping(value = "/del", method = { RequestMethod.GET, RequestMethod.POST })public Map
del(Long id,HttpServletRequest request){ Map
map = new HashMap<>(); try{ ptService.delPT(id); logger.debug("delsuccess....."); map.put("result", "chenggong"); map.put("msg", "删除信息成功!"); }catch(Exception e){ map.put("result", "shibai"); map.put("msg", "删除信息失败!"); } map.put("data", id); return map; }/** * 获取根据条件获取县域平台 查询当前系统和他的子集 * @param rows * @param page * @param status * @param details * @return */@ResponseBody@RequestMapping(value = "/getlist", method = { RequestMethod.GET, RequestMethod.POST })public Map
getlist(){ Map
map = new HashMap<>(); //获取当前系统ID String id= System.getenv("SXSK_WEB_ROOT"); System.err.print("当前主系统ID:"+id); Long parentid = 1L; PT pt = null; PTVO vo = new PTVO(); //当前平台 if(id!=""){ parentid=Long.parseLong(id); pt = ptService.findById(parentid); }else { pt = ptService.findById(1l); } BeanUtils.copyProperties(pt, vo); // 组装条件组 ConditionGroup group = new ConditionGroup(); group.setSearchRelation(SearchRelation.AND); //条件 List
conditions = new ArrayList
(); /*if(BeanUtil.isNotEmpty(level)){ if(Long.valueOf(level)!=-1){ conditions.add(new SearchCondition("level", Operator.EQ, level)); } }*/ if(BeanUtil.isNotEmpty(parentid)){ if(Long.valueOf(parentid)!=-1){ conditions.add(new SearchCondition("parentid", Operator.EQ, parentid)); } } //把条件加到条件组中 group.setConditions(conditions); List
pts = ptService.findByConditions(group); if (BeanUtil.isNotEmpty(pts)) { vo.setChild(pts); map.put("data", vo); }else{ map.put("data",vo); } return map; }}

7.前端传参

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ include file="/assets/global.jsp"%>县级平台
<%-- --%>
县级平台
新增
平台标识:
网      址:
系统名称:
经度:
纬度:
网      址:
系统名称:
中心点:
经度
纬度
(请在地图上选择经纬度)
编辑
平台标识:
网      址:
系统名称:
经 度:
纬度:
信息
你确定要删除吗?

 

8效果

 

将不定期更新资源,欢迎持续关注


想获得更多的学习知识请关注微信公众号:西北码农或扫下方二维码

你可能感兴趣的文章
小P的故事——神奇的Dota 背包
查看>>
3G版iPad水货价普降最少200元 受新品发布冲击
查看>>
转载《“精”、“气”、“神”解》
查看>>
Tilera平台使用体会
查看>>
NSString 转 UTF-8 的符号匹配问题
查看>>
Mysql 连接错误之-caching_sha2_password
查看>>
C#3.0智能的编译器
查看>>
代码修改mac地址(需要root)
查看>>
oracle错误
查看>>
转:开火,移动-大神Joel 也浮躁
查看>>
Java微笔记(8)
查看>>
快速查找素数 http://acm.nyist.net/JudgeOnline/problem.php?pid=187
查看>>
深度数据对接 链接服务器 数据传输
查看>>
【解决方法】Ubuntu文本编辑器gedit打开中文出现乱码的
查看>>
[摘录]第一章 华为高效执行密码
查看>>
查看数据库账号
查看>>
Thread常用方法
查看>>
python基础===修改属性的值
查看>>
selenium===requestium模块介绍
查看>>
grpc错误处理
查看>>