1、使用的是eclipse
2、本次创建的是client端,server是已存在的

  • 首先新创建一个Spring Starter Project

  • 填写项目基本信息

  • 选取项目需要的依赖(后期也可以在pom.xml中补充),选择后,点击finish

  • 这是项目创建后,中间有些包是我自己创建的,可以按照需要补充

  • 这是application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/springcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT&useAffectedRows=true&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.configuration.map-underscore-to-camel-case=true#设置SpringCloud
spring.application.name=system-springclouddemoserver.port=10090#使用ip地址向eureka注册中心注册
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ip-address}:${spring.application.instance_id:${server.port}}
eureka.client.service-url.defaultZone=http://**********/eureka/mybatis.type-aliases-package=com.****.zgy.entityspring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/templates/
  • 下面是pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.1</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.*****.zgy</groupId><artifactId>system-springclouddemo1</artifactId><version>${project.release.version}</version><name>system-springclouddemo1</name><description>Demo project for Spring Boot</description><!-- 指定了依赖的版本信息 --><properties><project.release.version>1.0.0-SNAPSHOT</project.release.version><java.version>8</java.version><spring-cloud.version>2020.0.0</spring-cloud.version></properties><!-- 多环境配置 --><profiles><profile><id>dev</id></profile><profile><id>prod</id><properties><project.release.version>1.0.0</project.release.version></properties></profile></profiles><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jdbc</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><!-- 可以使用@entity等注解 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- 为pojo类提供持久化 --><dependency><groupId>javax.persistence</groupId><artifactId>persistence-api</artifactId><version>1.0.2</version></dependency><!--访问静态资源--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url></repository></repositories></project>
  • 启动类
package com.*****.zgy;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;@SpringBootApplication
@ComponentScan("com.*****.zgy.controller,com.*****.zgy.dao,com.*****.zgy.entity,com.*****.zgy.service")
public class SystemSpringclouddemo1Application {public static void main(String[] args) {SpringApplication.run(SystemSpringclouddemo1Application.class, args);}}
  • controller

package com.***.zgy.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;import com.***.zgy.entity.Product;
import com.***.zgy.service.ProductService;@RestController
@RequestMapping("/Product")
public class SearchProductController {@Autowiredprivate ProductService productService;@RequestMapping("/")public ModelAndView goHome() {System.out.println("get OK");return new ModelAndView("index");}@RequestMapping(value = "/SearchProduct/{id}", method = RequestMethod.GET,produces = "application/json;charset=utf-8")public Product SearchProductById(@PathVariable Integer id) {Product product = productService.SearchProductById(id);return product;}}
  • dao
package com.***.zgy.dao;import org.apache.ibatis.annotations.Mapper;import com.***.zgy.entity.Product;@Mapper
public interface ProductMapper {Product SearchProductById(Integer id);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.***.zgy.dao.ProductMapper"><select id="SearchProductById" parameterType="int" resultType="com.***.zgy.entity.Product">select * from tb_product where id = #{ID}</select>
</mapper>
  • entity实体类
package com.***.zgy.entity;import javax.persistence.Entity;
import javax.persistence.Id;import lombok.Data;@Entity
@Data
public class Product {@Idprivate Integer ID;private String productName;private Integer status;private Double price;private String productDesc;private String caption;private Integer inventory;
}
  • service
package com.***.zgy.service;import org.springframework.stereotype.Service;import com.***.zgy.entity.Product;@Service
public interface ProductService {Product SearchProductById(Integer id);}
package com.***.zgy.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import com.***.zgy.dao.ProductMapper;
import com.***.zgy.entity.Product;@Service
public class ProductServiceImpl implements ProductService {@Autowiredprivate ProductMapper productMapper;@Overridepublic Product SearchProductById(Integer id) {// TODO Auto-generated method stubProduct product = productMapper.SearchProductById(id);return product;}}

至此结束。如有不妥,还望指正。谢谢^ _ ^

Eclipse搭建SpringCloud+SSM+Maven项目相关推荐

  1. 搭建eclipse版的ssm+maven+tk.mybatis+redis及mybatis+spring多数据源配置集成的demo

    前言:我这里搭建好eclipse版的ssm+maven+tk.mybatis+redis及mybatis+spring多数据源配置集成的demo.新手快速上手直接看demo. 最后处提供完整高质量de ...

  2. 使用eclipse创建基于SSM+Maven的小项目(简单的增删改查)

    使用eclipse创建基于SSM+Maven的增删改查 开发环境 效果图 数据库 项目如下: 项目结构及pom.xml 资源文件夹 db.properties mybatis-config.xml a ...

  3. 腾讯云轻量应用服务器CentOS系统使用docker安装tomcat,MySQL 并发布SSM maven项目

    腾讯云轻量应用服务器CentOS系统使用docker安装tomcat,MySQL 并发布SSM maven项目(记录) 一.服务器修改密码(此时已安装CentOS系统) 二.防火墙添加规则 三.连接X ...

  4. docker-comose搭建sonarqube 及 maven项目使用

    docker-comose搭建sonarqube 及 maven项目使用 前言 一.sonarqube 简介 二.docker及docker-compose安装 三.docker-compose安装s ...

  5. eclipse java maven_Eclipse构建maven项目

    Eclipse构建maven项目 1 Maven项目转为Eclipse项目 在项目的根目录下打开cmd:执行命令:mvn eclipse:eclipse :将会出现.classpath和.projec ...

  6. 7.Eclipse中创建新Maven项目

     第一步:首先导入前面命令行建立的两个maven项目Hello和HelloFriend. 方法:选择file-->import-->Existing MAVEN PROJECTS选项选 ...

  7. eclipse不识别java,在Eclipse中运行的Maven项目存在问题,无法识别为Java项目

    我已经将现有的maven项目导入Eclipse.我试图为JUnit测试设置配置,但是我的项目不会成为可测试项目.当我手动输入项目名称时,收到以下消息: 指定的项目不是Java项目 我还注意到,在键入代 ...

  8. Eclipse搭建java分布式商城项目

    博主也是在学习,看到一篇博客,自己一边学习,一边写下了这篇博客 项目模块划分 ycshop-parent: 父工程, 其打包方式是 pom, 主要管理 jar 包的版本号. 项目中的所有工程都应该继承 ...

  9. Eclipse创建一个普通maven项目详细步骤

    首先找到Eclipse最顶部左边的File,new一个 Maven Project项目 下一步,勾选第二个即可 下一步,选择  maven-archetype-webapp Group Id 写域名倒 ...

最新文章

  1. 二叉树的中序遍历(递归)
  2. IslandViewer4|基因组岛在线预测
  3. CCF201612-3 权限查询(100分)
  4. XCode 7上传遇到ERROR ITMS-90535 Unexpected
  5. hive与hbase整合方式和优劣
  6. 带有输出参数的存储过程
  7. Scrapy框架初探
  8. [Elasticsearch] es 6.8 编译报错 invalid type code: 85
  9. python中argsort_numpy的argsort函数
  10. 海量数据库解决方案2011022101
  11. 查询相关股票十档行情的方法
  12. python零基础入门视频免费-阿里云免费推出Python零基础入门在线教程视频
  13. Assignment 双向队列
  14. lan pci 联想开机_我的联想电脑开机老显示DHCP
  15. 在C#中什么时候用分号?
  16. Bengio最新博文:深度学习展望
  17. zabbix(三)—— update
  18. Netsparker
  19. Linux自学:常用删除命令(rm)使用方法
  20. 安装多个电脑杀毒软件

热门文章

  1. 网络加速和优化控制常用管理
  2. 分段路由:一个新的SDN内部技术—Vecloud
  3. 什么是控制单元?—Vecloud微云
  4. 服务器架构有哪些方式?—Vecloud微云
  5. 如何扩展CentOS7的SWAP分区
  6. CF1037H Security——SAM+线段树合并
  7. POJ 2387 Til the Cows Come Home
  8. 资源文件的读取和使用
  9. 新的html页面拼接类库(简易的模板引擎)
  10. 63.死锁和死锁的原因