1. 程式人生 > >架構-Eureka:第一個方法

架構-Eureka:第一個方法

返回頂部 autowired sel bin pre html doctype 返回 ica

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:第一個方法