既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
private String getResult(String string) throws SQLException {
PGgeometry pGgeometry = new PGgeometry(string);
String s = pGgeometry.toString();
return s.replace("SRID=4326;", "");
}
}
注意,在getResult()中关于4326坐标系的定义,可以根据需要进行废弃。这里写上为了统一投影坐标系。
### 三、在数据中创建表,建表语句如下:
create table biz_point_test(
id int8 primary key,
name varchar(100),
geom geometry(Point,4326)
);
### 四、定义Mybatis-plus实体
package com.hngtghy.project.extend.student.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hngtghy.framework.handler.PgGeometryTypeHandler;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@TableName(value =“biz_point_test”,autoResultMap = true)
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
@ToString
public class PointTest {
@TableId
private Long id;
private String name;
@TableField(typeHandler = PgGeometryTypeHandler.class)
private String geom;
@TableField(exist=false)
private String geomJson;
}
提醒:1、在属性上使用@TableField(typeHandler=xxx)来指定对应的类型转换器。2、需要在实体上定义autoResultMap=true。否则配置不一定生效。
### 五、定义mapper查询器
package com.hngtghy.project.extend.student.mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hngtghy.project.extend.student.domain.PointTest;
public interface PointTestMapper extends BaseMapper{
static final String FIND_GEOJSON_SQL="<script>"
+ "select st_asgeojson(geom) as geomJson from biz_point_test "
+ "where id = #{id} "
+ "<if test='null != name'>and p.name like concat('%', #{name}, '%')</if>"
+ "</script>";
@Select(FIND_GEOJSON_SQL)
PointTest findGeoJsonById(@Param("id")Long id,@Param("name")String name);
}
### 六、定义service业务类
package com.hngtghy.project.extend.student.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hngtghy.project.extend.student.domain.PointTest;
import com.hngtghy.project.extend.student.mapper.PointTestMapper;
import com.hngtghy.project.extend.student.service.IPointTestService;
@Service
public class PointTestServcieImpl extends ServiceImpl<PointTestMapper, PointTest> implements IPointTestService{
@Autowired
private PointTestMapper pointMapper;
@Override
public PointTest selectById(Long id) {
return pointMapper.selectById(id);
}
@Override
public List<PointTest> selectList(PointTest point) {
QueryWrapper<PointTest> queryWrapper = new QueryWrapper<PointTest>();
queryWrapper.select("id,name");
return this.getBaseMapper().selectList(queryWrapper);
}
@Override
public int insertPointTest(PointTest point) {
return pointMapper.insert(point);
}
@Override
public int updatePoint(PointTest point) {
return pointMapper.updateById(point);
}
@Override
public PointTest selectGeomById(Long id) {
QueryWrapper<PointTest> queryWrapper = new QueryWrapper<PointTest>();
queryWrapper.select("geom","st_asgeojson(geom) as geomJson");
queryWrapper.eq("id", id);
return this.getBaseMapper().selectOne(queryWrapper);
}
@Override
public PointTest findGeoJsonById(Long id) {
return pointMapper.findGeoJsonById(id, null);
}
}
这里添加了一个数据库不存在的字段geomJson,会将空间属性转变成geojson字段,方便于前台的如leaflet、openlayers、cesium等组件进行展示。所以使用postgis的st\_asgeojson(xxx)进行函数转换。
**七、相关方法调用**
//1、列表查询List pointList = pointService.selectList(null);System.out.println(pointList);
[PointTest(id=1559371184090423297, name=中寨居委会, geom=null, geomJson=null), PointTest(id=2, name=禾滩村, geom=null, geomJson=null), PointTest(id=1559403683801796610, name=中寨居委会, geom=null, geomJson=null)]
//2、插入PointTest point = new PointTest();point.setName(“中寨居委会”);point.setGeom(“POINT(109.262605 27.200669)”);//POINT(lng,lat) 经度,纬度pointService.insertPointTest(point);
//3、查询数据 PointTest point = pointService.selectGeomById(1559371184090423297L); PointTest json = pointService.findGeoJsonById(1559371184090423297L);
PointTest(id=null, name=null, geom=POINT(109.262605 27.200669), geomJson={“type”:“Point”,“coordinates”:[109.262605,27.200669]})PointTest(id=null, name=null, geom=null, geomJson={“type”:“Point”,“coordinates”:[109.262605,27.200669]})
### 八、使用pgadmin可以查看到相应的点数据,如下图所示:
![img](https://img-blog.csdnimg.cn/img_convert/13a4e24e5896174f9e04f0807b0cb7b4.png)
![img](https://img-blog.csdnimg.cn/img_convert/2888721e041ca58df97d5c6b3e11d8c5.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**