orcal 數據庫 maven架構 ssh框架 的全註解環境模版 maven中央倉庫批量刪除lastupdated文件後依然是lastupdated解決方法 mirror aliyun中央倉庫

批量刪除文件,得用批處理文件,文件名隨便,路徑改爲你的Repository,代碼以下html

rem 這裏寫你的倉庫路徑
set REPOSITORY_PATH=d:\repo
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
    del /s /q %%i
)
rem 搜索完畢
pause

刪除後還來updated,鬱悶死你時,不防切換到aliyun的倉庫java

<mirror>  
     <id>alimaven</id>  
     <name>aliyun maven</name>  
     <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
     <mirrorOf>central</mirrorOf>          
 </mirror> 

把下面代碼放到你的maven軟件的settings.xml文件的<mirrors>標籤中mysql

這樣就所有下載了,阿里仍是蠻強的web

建立maven項目後pom.xml 以下,這樣基本jar包就不用操心redis

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.swift</groupId>
    <artifactId>ssh-maven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

  <name>通用父工程</name>
   <properties>
        <spring.version>4.2.4.RELEASE</spring.version>
        <struts2.version>2.3.24</struts2.version>
        <hibernate.version>5.0.7.Final</hibernate.version>
        <slf4j.version>1.6.6</slf4j.version>
        <springdataredis.version>1.4.1.RELEASE</springdataredis.version>
        <activemq.version>5.14.5</activemq.version>
        <shiro.version>1.2.2</shiro.version>
        <springdatajpa.version>1.10.4.RELEASE</springdatajpa.version>
        <jedis.version>2.6.2</jedis.version>
        <poi.version>3.11</poi.version>
        <c3p0.version>0.9.1.2</c3p0.version>
        <cxf.version>3.0.1</cxf.version>
        <servlet.version>2.5</servlet.version>
        <junit.version>4.11</junit.version>
    </properties>

    <dependencies>
        <!-- 權限控制 框架 -->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-all</artifactId>
            <version>${shiro.version}</version>
        </dependency>

        <!-- spring 框架 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- spring data jpa 數據庫持久層 -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${springdatajpa.version}</version>
        </dependency>

        <!-- 消息隊列 MQ -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-spring</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-kahadb-store</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-broker</artifactId>
            <version>${activemq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-client</artifactId>
            <version>${activemq.version}</version>
        </dependency>

        <!-- struts2 框架 -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>javassist</groupId>
                    <artifactId>javassist</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <!-- hibernate 框架 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- 數據庫鏈接池 -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>mchange-commons-java</artifactId>
            <version>0.2.12</version>
        </dependency>
        <!-- 日誌框架 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <!-- 工具包 -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <!-- redis nosql 內存數據庫 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>${jedis.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>${springdataredis.version}</version>
        </dependency>

        <!-- oracle數據庫驅動,須要手動安裝 -->
        <!-- <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> 
            <version>11.2.0.1.0</version> </dependency> -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <version>10.2.0.1.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <!-- Excel解析工具類 -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>${poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>${poi.version}</version>
        </dependency>

        <!-- Servlet、JSP -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>${servlet.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- 單元測試 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- 導入webservice依賴 -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-rs-client</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-rs-extension-providers</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jettison</groupId>
            <artifactId>jettison</artifactId>
            <version>1.3.7</version>
        </dependency>

        <!-- 對象轉爲json 工具包 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.1.37</version>
        </dependency>

        <dependency>
            <groupId>com.colobu</groupId>
            <artifactId>fastjson-jaxrs-json-provider</artifactId>
            <version>0.3.1</version>
        </dependency>
        <!-- 引入json-lib的依賴 -->
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j -->
        <dependency>
            <groupId>com.belerweb</groupId>
            <artifactId>pinyin4j</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>${jedis.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        <!-- 緩存 -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.6.11</version>
        </dependency>
        <!-- 定時器|定時任務 -->
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz-jobs</artifactId>
            <version>2.2.1</version>
        </dependency>
        <!-- 阿里雲發送短信涉及的jar包 -->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>3.2.9</version>
        </dependency>
        <!-- 該座標,中央倉庫中沒有,須要手動導入到本地倉庫纔好使 -->
         <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jsp-api</artifactId>
             <version>2.0</version>
             <scope>provided</scope>
         </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

插件<artifactId>maven-compiler-plugin</artifactId>的做用:若是你設置了jdk的版本爲1.7,那麼spring

每次右鍵項目名->maven->update project 時候,項目jdk版本,不會變回1.8版本或者其餘版本sql

web端開始struts2數據庫

一個註解actionapache

package com.itheima.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.domain.Customer;
import com.itheima.service.CustomerService;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("struts-default")
@Namespace("/")
@Results({
        @Result(name="index",location="/index.jsp")
})
@Controller
@Scope("prototype")
public class CustomerAction extends ActionSupport {

    private Integer cid;
    private String name;
    private Customer cus;
    private CustomerService customerService;
    
    public void setName(String name) {
        this.name = name;
    }
    @Autowired
    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }
    public Customer getCus() {
        return cus;
    }
    public void setCid(Integer cid) {
        this.cid = cid;
    }

    @Action("CustomerAction_findById")
    public String findById() throws Exception {
        
        cus=customerService.findById(cid);
        return "list";
    }
    @Action("CustomerAction_add")
    public String add() throws Exception {
        
        Customer customer=new Customer();
        customer.setName(name);
        customerService.add(customer);
        return "index";
    }
}

無需struts.xmljson

測試網頁

index.jsp

複製代碼
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
歡迎您登陸首頁

<hr />
    <form action="${pageContext.request.contextPath }/CustomerAction_findById" method="post">
    <span>請輸入客戶編號:</span>
    <input type="text" name="cid" >
    <input type="submit" value="查詢" >
    </form>
<hr />
    <form action="${pageContext.request.contextPath }/CustomerAction_add" method="post">
    <span>請錄入客戶姓名:</span>
    <input type="text" name="name" >
    <input type="submit" value="增長" >
    </form>
</body>
</html>
複製代碼

顯示結果頁list.jsp

複製代碼
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <table>
        <tr>
            <td>編號:</td><td><input type="text" value="${cus.cid }"></td>
        </tr>
        <tr>
            <td>姓名:</td><td><input type="text" value="${cus.name }"></td>
        </tr>
    </table>
</body>
</html>
複製代碼

須要開啓struts的filter,(struts2就靠這個了)

web.xml

複製代碼
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>ssh-maven</display-name>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
複製代碼

實體類無需映射文件

package com.itheima.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity(name="tb_c")
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column
    private Integer cid;
    @Column
    private String name;
    public Integer getCid() {
        return cid;
    }
    public void setCid(Integer cid) {
        this.cid = cid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public String toString() {
        return "Customer [cid=" + cid + ", name=" + name + "]";
    }
    public Customer(Integer cid, String name) {
        this.cid = cid;
        this.name = name;
    }
    public Customer() {
    }
    
}

CustomerDaoImpl.java 持久層實現類

package com.itheima.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.itheima.domain.Customer;
@Repository
public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao{
    
    @Autowired
    public void setSF(SessionFactory sf){
        super.setSessionFactory(sf);
    }

    public Customer findById(Integer cid) {
        return this.getHibernateTemplate().get(Customer.class, cid);
    }

    @Override
    public void add(Customer customer) {

        this.getHibernateTemplate().save(customer);
    }

}

service層

package com.itheima.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.dao.CustomerDao;
import com.itheima.domain.Customer;


@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {

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


    public Customer findById(Integer cid) {

        return customerDao.findById(cid);
    }


    @Override
    public void add(Customer customer) {

        customerDao.add(customer);
    }

}

鏈接的庫 db.properties

複製代碼
driverClass = oracle.jdbc.driver.OracleDriver
jdbcUrl=jdbc:oracle:thin:@192.168.189.101:1521:orcl
user=scott
password=tiger
#driverClass = com.mysql.jdbc.Driver
#jdbcUrl=jdbc:mysql://localhost:3306/maven
#user=root
#password=root
複製代碼

以及最後的spring核心配置文件進行整合

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    <!-- 開啓ioc註解掃描 -->
    <context:component-scan base-package="com.itheima"></context:component-scan>
    
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- dataSource數據源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${driverClass}"></property>
        <property name="jdbcUrl" value="${jdbcUrl}"></property>
        <property name="user" value="${user}"></property>
        <property name="password" value="${password}"></property>
    </bean>
    
    <!-- 使用Spring整合Hibernate框架 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- hibernate配置文件,顯示SQL語句,生成表結構,格式化,數據庫方言 -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <!-- 掃描entity類 -->
        <property name="packagesToScan" value="com.itheima.domain"/>
    </bean>
    
    <!-- 事務管理器 -->
        <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" >
            <property name="sessionFactory" ref="sessionFactory" ></property>
        </bean>
        <!-- 開啓註解管理事務 -->
        <tx:annotation-driven transaction-manager="transactionManager" />
</beans>

無需hibernate.cfg.xml

各層接口

package com.itheima.dao;

import com.itheima.domain.Customer;

public interface CustomerDao {

    public Customer findById(Integer cid);

    public void add(Customer customer);
}
package com.itheima.service;

import com.itheima.domain.Customer;

public interface CustomerService {

    Customer findById(Integer cid);

    void add(Customer customer);

}
相關文章
相關標籤/搜索