架构-Eureka:第一个方法
Posted storebook
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了架构-Eureka:第一个方法相关的知识,希望对你有一定的参考价值。
ylbtech-架构-Eureka:第一个方法 |
工程介绍
Spring Cloud
工程目录
- model
- registry-center
- Servers
- tzxyfx
- tzxyfx-provider
- zinpkin
启动流程
1.运行注册中心
运行工程方式如下:RunAs-->Java Application|(Alt+Shift+X,R)
2.运行客户端
3.运行服务端
4.
1. model返回顶部 |
2. registry-center返回顶部 |
3. Servers返回顶部 |
4. tzxyfx返回顶部 |
1、src/mian/java
1.1 com.tzxyfx
1.1.1 sbtz
controller
package com.tzxyfx.sbtz.controller; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.tzxyfx.common.util.user.UserInfoUtil; import com.tzxyfx.sbtz.entity.Sbtz; import com.tzxyfx.sbtz.service.SbtzService; /** * @Description 内容控制器 * @author gjx * @version v1.0 */ @Controller @RequestMapping("/sbtz") public class SbtzController { @Resource private SbtzService sbtzService; /** * 前沿咨询请求 * * @param model * @return */ @RequestMapping("/searchSbtz") public String searchSbtz(Sbtz sbtz) { sbtz.setArticleId("aaa"); List<Sbtz> sbtzList = sbtzService.searchSbtz(sbtz); System.out.println("======SbtzController_end=====" + sbtzList.size()); UserInfoUtil.getRequest().setAttribute("lxjs", sbtzList); System.out.println("======SbtzController_end====="); return "forward:/sbtz.html"; } }
entity
package com.tzxyfx.sbtz.entity; /** * * @Description * @author gjx * @date 2018年8月28日 下午2:32:36 * @version v1.0 */ public class Sbtz { private String articleId; private String articleTitle; public String getArticleId() { return articleId; } public void setArticleId(String articleId) { this.articleId = articleId == null ? null : articleId.trim(); } public String getArticleTitle() { return articleTitle; } public void setArticleTitle(String articleTitle) { this.articleTitle = articleTitle == null ? null : articleTitle.trim(); } }
service
package com.tzxyfx.sbtz.service; import java.util.List; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import com.tzxyfx.common.config.mvc.FullLogConfiguration; import com.tzxyfx.sbtz.entity.Sbtz; @FeignClient(value = "TZXYFX-PROVIDER", configuration = FullLogConfiguration.class, path = "/sbtz") public interface SbtzService { /** * * @param * @param * @return */ @RequestMapping(value = "/searchSbtz") List<Sbtz> searchSbtz(Sbtz sbtz); }
关联服务端代码 @FeignClient(value = "TZXYFX-PROVIDER", configuration = FullLogConfiguration.class, path = "/sbtz")
2、src/main/resources
2.1 mybatis
2.2 application-dev.properties
2.2 application.properties
3、src/main/webapp
3.1 css
3.2 images
3.3 js
3.4
-home.html 主页
-sbtz.html 设备台帐分析
-xmtz.html 电网诊断与评价
-zhjh.html 综合计划项目管控
4、
-src
--main
---java
----com.tzxyfx
-----common
-----sbtz
------controller
-------SbtzController.java
package com.tzxyfx.sbtz.controller; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.tzxyfx.common.util.user.UserInfoUtil; import com.tzxyfx.sbtz.entity.Sbtz; import com.tzxyfx.sbtz.service.SbtzService; /** * @Description 内容控制器 * @author gjx * @version v1.0 */ @Controller @RequestMapping("/sbtz") public class SbtzController { @Resource private SbtzService sbtzService; /** * 前沿咨询请求 * * @param model * @return */ @RequestMapping("/searchSbtz") public String searchSbtz(Sbtz sbtz) { sbtz.setArticleId("aaa"); List<Sbtz> sbtzList = sbtzService.searchSbtz(sbtz); System.out.println("======SbtzController_end=====" + sbtzList.size()); UserInfoUtil.getRequest().setAttribute("lxjs", sbtzList); System.out.println("======SbtzController_end====="); return "forward:/sbtz.html"; } }
------entity
package com.tzxyfx.sbtz.entity; /** * * @Description * @author gjx * @date 2018年8月28日 下午2:32:36 * @version v1.0 */ public class Sbtz { private String articleId; private String articleTitle; public String getArticleId() { return articleId; } public void setArticleId(String articleId) { this.articleId = articleId == null ? null : articleId.trim(); } public String getArticleTitle() { return articleTitle; } public void setArticleTitle(String articleTitle) { this.articleTitle = articleTitle == null ? null : articleTitle.trim(); } }
------service
package com.tzxyfx.sbtz.service; import java.util.List; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import com.tzxyfx.common.config.mvc.FullLogConfiguration; import com.tzxyfx.sbtz.entity.Sbtz; @FeignClient(value = "TZXYFX-PROVIDER", configuration = FullLogConfiguration.class, path = "/sbtz") public interface SbtzService { /** * * @param * @param * @return */ @RequestMapping(value = "/searchSbtz") List<Sbtz> searchSbtz(Sbtz sbtz); }
-----sys
-----TzxyfxApplication.java
package com.tzxyfx; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; import com.base.util.redis.RedisCache; @SpringBootApplication @EnableFeignClients @EnableDiscoveryClient public class TzxyfxApplication { public static void main(String[] args) { SpringApplication.run(TzxyfxApplication.class, args); } @Bean public RedisCache redisCache(){ return new RedisCache(); } }
----com
---resoureces
---mybatis
----mapper
-----mybatis_trainingNeeds.xml
-----mybatis_user.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.tzxyfx.sys.dao.UserDao"> <resultMap type="com.tzxyfx.sys.entity.User" id="userLoginMap"> <id property="userId" column="USER_ID"/> <result property="loginName" column="LOGIN_NAME"/> <result property="userName" column="NAME"/> <result property="state" column="STATE"/> <result property="orgId" column="ORG_ID"/> <result property="password" column="PASSWORD"/> <result property="identityNo" column="IDENTITY_NO"/> <result property="mobile" column="MOBILE"/> <result property="email" column="EMAIL"/> <result property="officePhone" column="OFFICE_PHONE"/> <result property="type" column="TYPE"/> <result property="updateDate" column="UPDATE_DATE"/> <result property="orderNo" column="ORDER_NO"/> <!-- 需要添加Connction 角色信息 --> <collection property="roles" ofType="com.base.entity.Role" javaType="java.util.ArrayList"> <result column="ROLE_ID" property="roleId" jdbcType="VARCHAR" /> <result column="SYSTEM_ID" property="systemId" jdbcType="VARCHAR" /> <result column="ROLE_NAME" property="roleName" jdbcType="VARCHAR" /> </collection> </resultMap> <!-- 根据账号来获取用户信息 --> <select id="findByLogin" parameterType="java.lang.String" resultMap="userLoginMap"> select u.*,r.role_id as role_id,r.role_name as role_name from t_user u inner join t_user_role ur on u.user_id = ur.user_id inner join t_role r on r.role_id = ur.role_id where u.login_name = #{login} </select> </mapper>
----mybatis-config.xml
---application-dev.properties
---application.properties
---webapp
--test
5、
6、
5. tzxyfx-provider返回顶部 |
1、
src
-main
--java
---com.tzxyfx
----common.config
----sbtz
-----conf
------controller
-------SbtzController.java
package com.tzxyfx.sbtz.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.tzxyfx.sbtz.entity.Sbtz; import com.tzxyfx.sbtz.service.SbtzService; /* * 类描述: role 的controller 层 * @auther wangmx */ @RestController @RequestMapping("/sbtz") public class SbtzController { @Autowired private SbtzService sbtzService; @RequestMapping(value = "/searchSbtz") public List<Sbtz> searchSbtz(@RequestBody Sbtz sbtz){ List<Sbtz> sbtzList = sbtzService.searchSbtz(sbtz); return sbtzList; } }
------dao
-------SbtzDao.java
package com.tzxyfx.sbtz.dao; import java.util.List; import com.tzxyfx.sbtz.entity.Sbtz; /** * @author lc **/ public interface SbtzDao { /** * 关联 查询 * * @param entity * 查询 条件 */ List<Sbtz> searchSbtz(String sbtz); }
------entity
-------Sbtz.java
package com.tzxyfx.sbtz.entity; /** * * @Description * @author gjx * @date 2018年8月28日 下午2:32:36 * @version v1.0 */ public class Sbtz { private String articleId; private String articleTitle; private String userId; private String loginName; public String getArticleId() { return articleId; } public void setArticleId(String articleId) { this.articleId = articleId == null ? null : articleId.trim(); } public String getArticleTitle() { return articleTitle; } public void setArticleTitle(String articleTitle) { this.articleTitle = articleTitle == null ? null : articleTitle.trim(); } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getLoginName() { return loginName; } public void setLoginName(String loginName) { this.loginName = loginName; } }
------service
-------imp
--------SbtzServiceImpl.java
package com.tzxyfx.sbtz.service.imp; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.tzxyfx.sbtz.dao.SbtzDao; import com.tzxyfx.sbtz.entity.Sbtz; import com.tzxyfx.sbtz.service.SbtzService; /** * @author lc **/ @Service @Transactional public class SbtzServiceImpl implements SbtzService{ @Autowired private SbtzDao sbtzDao; @Override public List<Sbtz> searchSbtz(Sbtz sbtz) { List<Sbtz> lis = null; try { lis = sbtzDao.searchSbtz(sbtz.getArticleId()); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception } return lis; } }
-------SbtzService.java
package com.tzxyfx.sbtz.service; import java.util.List; import com.tzxyfx.sbtz.entity.Sbtz; /** * @author lc **/ public interface SbtzService { /** * 功能描述:加载用户的菜单树的数据 * * @param user * @return */ public List<Sbtz> searchSbtz(Sbtz sbtz); }
----sys
----TzxyfxPApplication.java
package com.tzxyfx; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Bean; import com.base.util.redis.RedisCache; @SpringBootApplication public class TzxyfxPApplication { public static void main(String[] args) { SpringApplication.run(TzxyfxPApplication.class, args); } /** * 功能描述:注入redis * @return */ @Bean public RedisCache redisCache(){ return new RedisCache(); } }
---com
----com.tzxyfx
--resources
---mybatis
----mapper
-----mybais_SbtzMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.tzxyfx.sbtz.dao.SbtzDao"> <resultMap type="com.tzxyfx.sbtz.entity.Sbtz" id="SbtzMap"> <id property="userId" column="USER_ID"/> <result property="loginName" column="LOGIN_NAME"/> </resultMap> <!-- 查询 + --> <select id="searchSbtz" resultMap="SbtzMap"> select * from t_user where name like ‘赵云%‘ </select> </mapper>
-----mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <typeAlias alias="Integer" type="java.lang.Integer" /> <typeAlias alias="Long" type="java.lang.Long" /> <typeAlias alias="HashMap" type="java.util.HashMap" /> <typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" /> <typeAlias alias="ArrayList" type="java.util.ArrayList" /> <typeAlias alias="LinkedList" type="java.util.LinkedList" /> </typeAliases> </configuration>
----application-dev.properties
----application.properties
-test
2、
3、
4、
5、
6、
6. zinpkin 返回顶部 |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
以上是关于架构-Eureka:第一个方法的主要内容,如果未能解决你的问题,请参考以下文章
springcloud-第一个神兽“Eureka”-高可用的搭建(2-1)
微服务架构 SpringCloudEureka(注册中心集群篇)