zoukankan      html  css  js  c++  java
  • Dubbo实现登陆

    一、目录展示

        

    二、dubbo_logins_service

      2.1 实体类和service层

        

      2.2 logins实体类  

    package com.login.entity;
    
    import java.io.Serializable;
    
    public class logins implements Serializable {
    
        private Integer id;
    
        private String devcode;
    
        private String devname;
    
        private String devpassword;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public String getDevcode() {
            return devcode;
        }
    
        public void setDevcode(String devcode) {
            this.devcode = devcode;
        }
    
        public String getDevname() {
            return devname;
        }
    
        public void setDevname(String devname) {
            this.devname = devname;
        }
    
        public String getDevpassword() {
            return devpassword;
        }
    
        public void setDevpassword(String devpassword) {
            this.devpassword = devpassword;
        }
    
        public logins(Integer id, String devcode, String devname, String devpassword) {
            this.id = id;
            this.devcode = devcode;
            this.devname = devname;
            this.devpassword = devpassword;
        }
    
        public logins() {
        }
    }
    View Code

      2.3 loginsService层

    package com.login.service;
    
    import com.login.entity.logins;
    
    public interface loginsService {
        logins checkLogin(logins login);
    }
    View Code

    三、dubbo_logins

      3.1 dao层、serviceImpl实现类、resource配置文件

        

      3.2 loginsDao(SQL在内)

    package com.login.dao;
    
    import com.login.entity.logins;
    import org.apache.ibatis.annotations.Select;
    import org.springframework.stereotype.Repository;
    
    @Repository
    public interface loginsDao {
        //登陆的方法
        @Select("select * from dev_user where devcode=#{devcode} and devpassword=#{devpassword}")
        logins checkLogin(logins login);
    }
    View Code

      3.3 loginsImpl

    package com.login.impl;
    
    import com.login.dao.loginsDao;
    import com.login.entity.logins;
    import com.login.service.loginsService;
    import org.springframework.stereotype.Service;
    
    import javax.annotation.Resource;
    
    @Service("loginsService")
    public class loginsImpl implements loginsService {
    
        @Resource
        loginsDao loginsdao;
    
        @Override
        public logins checkLogin(logins login) {
            logins logins = loginsdao.checkLogin(login);
            if (logins!=null){
                if (logins.getDevpassword().equals(logins.getDevpassword())){
                    return  logins;
                }
            }
            return null;
        }
    }
    View Code

      3.4 applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
            xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
            http://code.alibabatech.com/schema/dubbo
            http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    
        <!--    导入数据库连接文件-->
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreUnresolvablePlaceholders" value="true" />
            <property name="location" value="classpath:jdbc.properties"/>
        </bean>
        <!--配置数据源-->
        <bean  id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="username" value="${jdbc.username}"/>
        </bean>
    
        <!--配置MyBatis的核心对象SqlSessionFactoryBean-->
        <bean id="SessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <!--创建包扫描器(借助dao接口实现动态代理)-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer           ">
            <property name="basePackage" value="com.login.dao"/>
        </bean>
        <context:component-scan base-package="com.login"/>
        <context:annotation-config/>
        <mvc:annotation-driven/>
    
    
        <!-- 提供方应用信息,用于计算依赖关系 -->
        <dubbo:application name="app-provider"/>
    
        <!-- 使用zookeeper注册中心暴露服务地址 -->
        <dubbo:registry address="127.0.0.1:2181"   protocol="zookeeper" />
    
        <!-- 用dubbo协议在20880端口暴露服务 -->
        <dubbo:protocol name="dubbo" port="20880" />
    
        <!-- 声明需要暴露的服务接口 -->
        <dubbo:service interface="com.login.service.loginsService" ref="loginsService" />
    </beans>
    View Code

      3.5 jdbc.properties连接数据库

         

       3.6 log4j.properties日志文件

       

      3.7 web.xml 配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1">
    
      <!--Spring和MyBatis整合的核心配置-->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      <!--配置SpringMVC的核心控制器DispatcherServlet-->
      <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath*:applicationContext.xml</param-value>
        </init-param>
      </servlet>
    
    
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    
    
      <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <!--设置映射路径,/代表所有的请求都会被核心控制器映射到对应的Controller中-->
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    
      <!--编码过滤器-->
      <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <!--初始化参数-->
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
      </filter>
    
      <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    </web-app>
    View Code

    四、dubbo_logins_controller

      4.1 controller层、resource配置文件、jsp页面  

        

      4.2 MyController

    package com.login.controller;
    
    
    import com.login.entity.logins;
    import com.login.service.loginsService;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    import javax.annotation.Resource;
    import javax.servlet.http.HttpServletResponse;
    
    @Controller
    @RequestMapping("/login")
    public class MyController {
        @Resource
        private loginsService loginsService;
        @RequestMapping("/checkLogin")
    
        public String checkLogin(logins logins, HttpServletResponse response){
            response.setCharacterEncoding("UTF-8");
            logins logins1 = loginsService.checkLogin(logins);
            if (logins1==null) {
                return "login";
            }
            return  "index";
        }
    }
    View Code

      4.3 applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
            http://code.alibabatech.com/schema/dubbo
            http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        <context:component-scan base-package="com.login"/>
        <mvc:annotation-driven/>
        <context:annotation-config/>
        <!-- 配置视图解析器,设置前缀和后缀,自动拼接 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- 前缀 -->
            <property name="prefix" value="/jsp/" />
            <!-- 后缀 -->
            <property name="suffix" value=".jsp" />
        </bean>
    
        <mvc:default-servlet-handler/>
        <!-- 提供方应用信息,用于计算依赖关系 -->
        <dubbo:application name="consumer"/>
    
        <!-- 使用zookeeper注册中心暴露服务地址 -->
        <dubbo:registry address="127.0.0.1:2181"   protocol="zookeeper" />
    
        <!-- 用dubbo协议在20880端口暴露服务 -->
        <dubbo:protocol name="dubbo" port="20880" />
    
        <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
        <dubbo:reference id="loginsService" interface="com.login.service.loginsService" />
    
    </beans>
    View Code

      4.4 log4j.properties日志文件

        

       4.5 login.jsp登陆页面

        

      4.6 index.jsp登陆成功页面

        

       4.7 web.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1">
    
      <!--Spring和MyBatis整合的核心配置-->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      <!--配置SpringMVC的核心控制器DispatcherServlet-->
      <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath*:applicationContext.xml</param-value>
        </init-param>
      </servlet>
    
    
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    
    
      <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <!--设置映射路径,/代表所有的请求都会被核心控制器映射到对应的Controller中-->
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    
      <!--编码过滤器-->
      <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <!--初始化参数-->
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
      </filter>
    
      <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    </web-app>
    View Code

    五、Tomcat配置

      

     

     六、效果展示

      

      

      

      

  • 相关阅读:
    Java-数据字符串进行四舍五入
    Git本地安装及汉化
    Navicat安装教程
    Jdk+maven安装
    系列文章
    @PathVariable
    feign组件
    Lombok
    常见Jar包的用途
    iOS archive(归档)的总结
  • 原文地址:https://www.cnblogs.com/Zzzzn/p/11970991.html
Copyright © 2011-2022 走看看