最近接手一个活,用springboot整合mybatis获取一批数据,上传到elastic search建索引。小小研究了一下,操作不多,没有很难。
很好的教程
http://www.sojson.com/blog/81.html
https://yq.aliyun.com/articles/70054
遇到比较典型的错:
错1
https://stackoverflow.com/questions/8367312/serializing-with-jackson-json-getting-no-serializer-found
No serializer found for class elasticSearch.LogModel and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
大意是模板类没有set方法,故报错。用对象转json的时候报的。
错2
http://blog.csdn.net/z69183787/article/details/22269131
Jackson2需要引3个maven包
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0.pr3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0.pr3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.0.pr3</version>
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9201}]]
这个是因为配置文件中没有配,网上有文章写创建conf,真是乱讲。(后来又报了一次这个错,是因为client连接关闭了还调用连接,spring的@autowire标签初始化类只调用一次构造方法,我创建连接的代码写构造方法里了,

当心client关闭后再次访问,会报找不着节点的错误。)
  1. $ vi config/elasticsearch.yml
  2. #cluster name
  3. cluster.name: sojson-application
  4. #节点名称
  5. node.name: node-1
  6. #绑定IP和端口
  7. network.host:123.88.88.88
  8. http.port:9200
还有在程序中创建连接时,端口写9300
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.0.106"), 9300));
9300端口: ES节点之间通讯使用
9200端口: ES节点 和 外部 通讯使用
我们这里是添加节点,故使用9300端口。
启动elastic search报错,用这个命令启动。
failed to delete temp file /Users/lasia/Software/elasticsearch-2.1.0/data/gafisperson/nodes/0/indices/person/1/translog/translog-4113158842387570706.tlog
java.nio.file.NoSuchFileException: /Users/lasia/Software/elasticsearch-2.1.0/data/gafisperson/nodes/0/indices/person/1/translog/translog-4113158842387570706.tlog
./elasticsearch -Des.insecure.allow.root=true -d
后台启动
做这个项目时还用到了springboot mybatis,操作数据库。
很简单,配置mapping.xml,再在类中添加方法就可以了。需要注意添加方法时sql语句的通配参数需要转换一下。
long minSeq(@Param("name")String name);
<select id="minSeq" resultType="long">
select seq from monad_load_config where name = #{name} and deletag = '1'
</select>
而且,map配置文件中有大于号小于号的时候,需要注意转义。
&lt; &gt;
<![CDATA[]]>
发现数据库查询的时候,要分根据seq分组查询,必须先进行排序,再切割(rownum<10),不然只会排切割的区间···还好发现的早,不然得丢好多数据···
SELECT * from (select lower(p.personid) as personid, p.fingerrepeatno as fingerrepeatno
from gafis_person p left join sys_depart d on p.gather_org_code = d.code left join code_ly ly on p.data_sources = ly.code ) m
WHERE m.seq >= 1 and ROWNUM <=10 ; 对勾
select lower(p.personid) as personid, p.fingerrepeatno as fingerrepeatno
from gafis_person p left join sys_depart d on p.gather_org_code = d.code left join code_ly ly on p.data_sources = ly.code
WHERE p.seq >= 1 and ROWNUM <=10; ❌
不久后又增加功能开放端口,删除整个索引,用标签@RequestMapping("/delete")来实现,在类上和方法上分别加这个标签。参数增加:@RequestParam("indexName") String indexName
再访问,http://127.0.0.1:8099/elastic/delete?indexName=sss
但要注意,标签内的字符串更改后不rebuild可能会认不出来。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
由于访问接口后返回404页面,这一点需要修改。
参考资料http://jinnianshilongnian.iteye.com/blog/1997192
将标签@Service改为@RestController
传参标签由@requestparam改为public String DeleteElastic(@PathVariable("deleteName") String deleteName) {配合
@RequestMapping("/delete/{deleteName}")使用
@PathVariable和@RequestParam,分别是从路径里面去获取变量,也就是把路径当做变量,后者是从请求里面获取参数。
/Springmvc/user/page.do?pageSize=3&pageNow=2 
pageSize和pageNow应该是属于参数而不是路径,所以应该添加@RequestParam的注解。 
如果做成如下URL,则可以使用@PathVariable 
/Springmvc/user/page/2/3.do 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
同时还需要注意@Controller和@RestController的区别
@RestController=@Controller+@Reponsebody
只写@Controller会映射到页面,加@Responsebody会直接当作返回结构体来处理,不会对应到页面。
http://blog.csdn.net/gg12365gg/article/details/51345601
,下面spring程序的代码片段可以直接return回数据,不然需要的是html格式的view。
[java] view plain copy
 print?
@RestController  
public class HelloController {  
  
    @RequestMapping("/")  
    public String index() {  
        return "Greetings from Spring Boot!";  //由于是@RestController,因此直接返回数据,而不是view  
    }  
  
}  
@Service和@Controller区别
@Service用于标注业务层组件
@Controller用于标注控制层组件(如struts中的action)

elasticsearch,spring boot,mybatis项目小结相关推荐

  1. 商城项目(一)使用Spring boot + Mybatis搭建

    Spring boot + Mybatis基础架构 环境搭建 mysql 8 mysql客户端连接工具 Valentina Studio springboot 版本:2.1.3.RELEASE Myb ...

  2. Eclipse + Spring boot +mybatis + mysql

    Eclipse + Spring boot +mybatis + mysql 如题.使用Springboot 2.0 版本进行网页的开发.原理和优点很多博文已经讲过了,这里不再赘述.但是很多项目按照他 ...

  3. 简单介绍基于Spring Boot的项目骨架使用

    前言 从大学开始接触 java 后台开发,到后来了解了更多的编程语言的开发.发现 java 的开发可以说是相较而言很复杂的了,光是 Spring MVC 的配置要是没有经历系统的学习,可能就能劝退一波 ...

  4. spring boot+mybatis整合

    LZ今天自己搭建了下Spring boot+Mybatis,比原来的Spring+SpringMVC+Mybatis简单好多.其实只用Spring boot也可以开发,但是对于多表多条件分页查询,Sp ...

  5. Spring boot Mybatis 整合(注解版)

    之前写过一篇关于springboot 与 mybatis整合的博文,使用了一段时间spring-data-jpa,发现那种方式真的是太爽了,mybatis的xml的映射配置总觉得有点麻烦.接口定义和映 ...

  6. Spring Boot + Mybatis 快速整合

    引言 最近在工作结束后抽时间学习了一下mybatis的知识,因为之前有学习过,但是经久不用,也未曾踏实地整理,因此有所淡忘. super meeting会议管理系统是我厂最近开发的一套会议预约平台.持 ...

  7. Spring Boot MyBatis

    MyBatis简介 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache 迁移到了google code,并且改名为MyBatis . 集成spring bo ...

  8. spring boot + mybatis + layui + shiro后台权限管理系统

    后台管理系统 版本更新 后续版本更新内容 链接入口: springboot + shiro之登录人数限制.登录判断重定向.session时间设置:https://blog.51cto.com/wyai ...

  9. 从零搭建一个 Spring Boot 开发环境!Spring Boot+Mybatis+Swagger2 环境搭建

    从零搭建一个 Spring Boot 开发环境!Spring Boot+Mybatis+Swagger2 环境搭建 本文简介 为什么使用Spring Boot 搭建怎样一个环境 开发环境 导入快速启动 ...

  10. Spring boot Mybatis 整合(完整版)

    Spring boot Mybatis 整合(完整版) 更多干货 SpringBoot系列目录 正题 本项目使用的环境: 开发工具:Intellij IDEA 2017.1.3 springboot: ...

最新文章

  1. 产品设计体会(1011)少做就是多做
  2. 存储过程--分页与C#代码调用
  3. css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法
  4. 机电传动控制第二周学习笔记
  5. eclipse中启动tomcat出现错误的解决方法
  6. (转载)大数据与企业的数据化运营
  7. 安装路径是什么意思_404 not found nginx是什么意思
  8. python怎么做乘法表_python怎么写乘法表
  9. 第六次作业:结对项目之需求分析与原型设计
  10. 20. 远程端口查看
  11. C++ API 设计 15 第十章 测试
  12. jsp入门教程:7个步骤实现JSP的分页显示
  13. php file_get_contents 失效,phpfile_get_contents返回空无效解决办法_PHP教程
  14. iOS 仿微信发送语音消息按钮 - 语音录音机(二)
  15. 降成本利器——SRM之电子招投标
  16. 初学习数据库,记录1,在sql server数据表主键中插入UUID
  17. Android 进阶——系统启动之Android进程造物者Zygote 进程启动详解(六)
  18. Thriving in a Crowded and Changing World C++ 2006–2020 (11 回顾)
  19. spring boot手工DIY网站毕业设计源码310226
  20. 文献阅读 2018 Deep Retinex Decomposition for low-light Enhancement

热门文章

  1. 风行python_Python是啥?竟然彻底改变了老板对我的看法……
  2. 自适应页界面HTML源码
  3. 《解构产品经理互联网产品策划入门》PDF+《互联网产品运营产品经理的10堂精英课》PDF分析...
  4. 小秘谈币|币圈永远不缺机会,就怕缺你在场内
  5. 深度linux软件中心 qq,ubuntu上安装QQ(包括多个软件安装方法)
  6. 祛痘收缩毛孔的简单方法 - 健康程序员,至尚生活!
  7. 视频教程-2019年人工智能热门案例精讲之歌词生成器-机器学习
  8. IE 无法正常打开,刚启动就关闭
  9. 各种网页播放面板代码,MediaPlayer Replayer等
  10. 线程池ThreadPoolExecutor与ForkJoinPool