资讯专栏INFORMATION COLUMN

ssh配置模版

LiuZh / 2668人阅读

摘要:父模块,作为项目顶层,用于包导入桥接告诉使用桥接使用也支持其他实现到的桥接,引入不同的包即可使用异步写日志功能必须引入此包

ssh-parent

父模块,作为项目顶层,用于jar包导入

pom.xml


    4.0.0

    chzu
    ssh-parent
    pom
    1.0-SNAPSHOT

    
        ssh-dao
        ssh-service
        ssh-web
    

    ssh-parent

    
        UTF-8
        1.8
        1.8
        5.3.1.Final
        2.5.16
        5.1.46
        5.0.6.RELEASE
        2.10.0
    

    
        
        
            javax.servlet
            javax.servlet-api
            4.0.0
            provided
        

        
            javax.servlet
            jsp-api
            2.0
            provided
        

        
            javax.servlet
            jstl
            1.2
            compile
        


        
        
            mysql
            mysql-connector-java
            ${mysql-connector-java.version}
        

        
        
            junit
            junit
            4.12
        

        
        
            org.apache.logging.log4j
            log4j-core
            ${log4j.version}
        
        
            org.apache.logging.log4j
            log4j-api
            ${log4j.version}
        
             
            org.apache.logging.log4j
            log4j-slf4j-impl
            ${log4j.version}
        
        
            org.slf4j
            
            log4j-over-slf4j
            1.7.25
        
        
        
            com.lmax
            disruptor
            3.4.2
        


        
        
            org.apache.struts
            struts2-core
            ${struts2.version}
        
        
        
            org.apache.struts
            struts2-spring-plugin
            ${struts2.version}
        
        
            org.apache.struts
            struts2-convention-plugin
            ${struts2.version}
        
        
            org.apache.struts
            struts2-json-plugin
            ${struts2.version}
        

        
        
            org.hibernate
            hibernate-core
            ${hibernate.version}
        
        
            org.hibernate
            hibernate-c3p0
            ${hibernate.version}
        
        
            c3p0
            c3p0
            0.9.1.2
        

        
        
            org.springframework
            spring-core
            ${spring.version}
        
        
            org.springframework
            spring-context
            ${spring.version}
        
        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-orm
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        
        
            org.springframework
            spring-aspects
            ${spring.version}
        
        
            org.springframework
            spring-jdbc
            ${spring.version}
        
        
            org.springframework
            spring-beans
            ${spring.version}
        
        
            org.springframework
            spring-test
            ${spring.version}
        
    
ssh-dao

数据访问层模块,用户与数据库交互,作为ssh-parent子模块

pom.xml


    
        ssh-parent
        chzu
        1.0-SNAPSHOT
    
    4.0.0
    ssh-dao
    
    
hibernate配置 db.properties
jdbc.url=jdbc:mysql:///maven_ssh
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.user=root
jdbc.password=root
hibernate.cfg.xml



    
        org.hibernate.dialect.MySQL5Dialect
        true
        true
        update

        
        
    
Customer.hbm.xml




    
        
            
        
        
        
    
spring配置 applicationContext-basic.xml

连接数据库基本配置




    
    

    
    
        
        
        
        
    

    
    
        
        
        
    

    
    
        
        
    


    
    
        
    

    
    
    
        
            
            
            
            
            
        
    

    
    
        
        

        
        
    

    
    
    
    


applicationContext-dao.xml

创建操作数据库对象




    
    

    
    
        
    

测试用例 Customer.java
public class Customer {

    private Integer customerId;

    private String customerName;

    private String customerPhone;
    ....setter getter
CustomerDao.java
public interface CustomerDao {

    /**
     * 根据ID查询客户
     * @param id 客户ID
     * @return 客户
     */
    Customer findById(Integer id);

}
CustomerDaoImpl.java
public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao {

    @Override
    public Customer findById(Integer id) {
        return this.getHibernateTemplate().get(Customer.class,id);
    }
}
CustomerDaoImplTest.java
public class CustomerDaoImplTest {

    @Test
    public void findById() {

        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("applicationContext-basic.xml", "applicationContext-dao.xml");

        CustomerDaoImpl customerDao = context.getBean("customerDao", CustomerDaoImpl.class);

        System.out.println(customerDao.findById(1));
    }
}
ssh-service pom.xml


    
        ssh-parent
        chzu
        1.0-SNAPSHOT
    
    4.0.0

    ssh-service

    
        
            chzu
            ssh-dao
            1.0-SNAPSHOT
        
    
spring配置文件 applicationContext-service.xml



    
    
        
    
测试用例

CustomerService.java

public interface CustomerService {
    /**
     * 根据ID查询客户
     * @param id 客户ID
     * @return 客户
     */
    Customer findById(Integer id);
}

CustomerServiceImpl.java

public class CustomerServiceImpl implements CustomerService {

    private CustomerDao customerDao;

    public void setCustomerDao(CustomerDao customerDao) {
        this.customerDao = customerDao;
    }

    @Override
    public Customer findById(Integer id) {
        return customerDao.findById(id);
    }
}

CutomerServiceDaoImplTest.java

public class CustomerServiceImplTest {

    @Test
    public void findById() {

        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("classpath*:applicationContext-*.xml");

        CustomerService customerService =
                context.getBean("customerService", CustomerService.class);

        System.out.println(customerService.findById(1));

    }
}
ssh-web pom.xml



    
        ssh-parent
        chzu
        1.0-SNAPSHOT
    
    4.0.0

    ssh-web
    war

    ssh-web

    
        UTF-8
        1.8
        1.8
    

    
        
            chzu
            ssh-service
            1.0-SNAPSHOT
            compile
        
    

    
        
            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.2
            
        
    
web.xml



    
    
        contextConfigLocation
        classpath*:applicationContext-*.xml
    
    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        struts2
        org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
    
    
        struts2
        /*
    

struts.xml




    
        
        regex:.*

        
            /index.jsp
            
            
        
    
log4j2.xml


    
        
            
        
    
    
        
            
        
    
spring配置 applicationContext-action.xml



  
    
        
    

测试用例 CustomerAction.java
package chzu.action;

import chzu.bean.Customer;
import chzu.service.CustomerService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CustomerAction extends ActionSupport {

    private CustomerService customerService;

    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }

    // 访问http://localhost:8080/ssh-web/customer_find?id=1
    // 访问http://localhost:8080/customer_find?id=1
    private String  id;

    public String getId() {
        return id;
    }
    // 注入属性
    public void setId(String id) {
        this.id = id;
    }

    public String find() throws Exception {

        Customer customer = customerService.findById(Integer.parseInt(id));

        ActionContext.getContext().getValueStack().set("customer",customer);

        return SUCCESS;
    }
}
index.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>


    index


    姓名:


文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/69728.html

相关文章

  • 谈谈Pod在微服务中的运用

    摘要:本文整理自时速云线上微信群分享第十期本文主要包括的基本概念使用场景,以及如何在时速云平台上进行的编排部署,希望对大家在进行微服务架构实践时有所帮助。问关于提供访问容器数据的能力,中包含一个业务和一个服务,时速云的控制台可以进入到容器内部。 本文整理自【时速云线上微信群分享】第十期 本文主要包括Pod的基本概念、使用场景,以及如何在时速云平台上进行Pod的编排部署,希望对大家在进行微服务...

    MASAILA 评论0 收藏0
  • 10分钟搭建ubuntu+nodejs+pm2自动部署+nginx+永久免费SSL证书+mongod

    摘要:将第二步中的安装源换成阿里云的镜像安装会比较快,如下将上面的部分替换如下更新源正式安装常用命令本地和服务器使用公钥免密访问仓库在使用协议访问项目仓库之前,需要先配置好账户项目的公钥。 如果你对nodejskoa2vuejs等感兴趣,请加QQ群:732189938 或者直接点击链接加入群聊【Node.js/Koa2/vuejs】:https://jq.qq.com/?_wv=1027&k...

    yeyan1996 评论0 收藏0
  • 10分钟搭建ubuntu+nodejs+pm2自动部署+nginx+永久免费SSL证书+mongod

    摘要:将第二步中的安装源换成阿里云的镜像安装会比较快,如下将上面的部分替换如下更新源正式安装常用命令本地和服务器使用公钥免密访问仓库在使用协议访问项目仓库之前,需要先配置好账户项目的公钥。 如果你对nodejskoa2vuejs等感兴趣,请加QQ群:732189938 或者直接点击链接加入群聊【Node.js/Koa2/vuejs】:https://jq.qq.com/?_wv=1027&k...

    godlong_X 评论0 收藏0
  • 10分钟搭建ubuntu+nodejs+pm2自动部署+nginx+永久免费SSL证书+mongod

    摘要:将第二步中的安装源换成阿里云的镜像安装会比较快,如下将上面的部分替换如下更新源正式安装常用命令本地和服务器使用公钥免密访问仓库在使用协议访问项目仓库之前,需要先配置好账户项目的公钥。 如果你对nodejskoa2vuejs等感兴趣,请加QQ群:732189938 或者直接点击链接加入群聊【Node.js/Koa2/vuejs】:https://jq.qq.com/?_wv=1027&k...

    YuboonaZhang 评论0 收藏0
  • Rancher v1.2震撼发布:更优秀的全栈化容器部署与管理平台

    摘要:模版用户可以选择不同的基础设施服务组成模版同时还是有默认的主要模版,用户可以快速创建用户也可以把的项目放到模版中,来管理和部署增强已经大大简化了管理和配置,在多节点部署中和已经被去掉了。请保持关注,和一起走上伟岸光明的容器之路 开篇第一句,先为Rancher v1.2曾经的跳票深深抱歉(鞠躬)。我们补偿的方式,就是在此日、此刻,用新版功能向你证明Rancher v1.2值得你的等待。R...

    NervosNetwork 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<