一、xml配置css
<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.sundablog</groupId> <artifactId>sunda-parent</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <properties> <junit.version>4.12</junit.version> <spring.version>4.3.14.RELEASE</spring.version> <mybatis.version>3.4.1</mybatis.version> <mybatis.spring.version>1.3.0</mybatis.spring.version> <mybatis.paginator.version>1.2.15</mybatis.paginator.version> <mysql.version>5.1.32</mysql.version> <slf4j.version>1.7.25</slf4j.version> <log4j2.version>2.8.2</log4j2.version> <jackson.version>2.9.0</jackson.version> <druid.version>1.0.29</druid.version> <httpclient.version>4.5.2</httpclient.version> <jstl.version>1.2</jstl.version> <servlet-api.version>2.5</servlet-api.version> <jsp-api.version>2.0</jsp-api.version> <servlet.version>3.1.0</servlet.version> <joda-time.version>2.9.9</joda-time.version> <commons-lang3.version>3.4</commons-lang3.version> <commons-io.version>1.3.2</commons-io.version> <commons-net.version>3.3</commons-net.version> <commons-compress.version>1.12</commons-compress.version> <pagehelper.version>4.2.1</pagehelper.version> <commons-fileupload.version>1.3.1</commons-fileupload.version> <jedis.version>2.9.0</jedis.version> <solrj.version>6.6.1</solrj.version> <dubbo.version>2.5.7</dubbo.version> <zookeeper.version>3.4.10</zookeeper.version> <zkclient.version>0.1</zkclient.version> <activemq.version>5.11.4</activemq.version> <freemarker.version>2.3.23</freemarker.version> <quartz.version>2.2.3</quartz.version> <shiro.version>1.3.2</shiro.version> <hutool.version>4.0.7</hutool.version> <mail.version>1.4.7</mail.version> <okhttp3.version>3.3.1</okhttp3.version> <gson.version>2.6.2</gson.version> <fastdfs.version>1.27-SNAPSHOT</fastdfs.version> <oshi-core.version>3.4.4</oshi-core.version> <fastjson.version>1.2.28</fastjson.version> <zxingcore.version>3.3.1</zxingcore.version> <beetl.version>2.7.27</beetl.version> </properties> <dependencyManagement> <dependencies> <!-- 獲取系統信息 --> <dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> <version>${oshi-core.version}</version> </dependency> <!-- 時間操做組件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>${joda-time.version}</version> </dependency> <!-- Apache工具組件 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>${commons-net.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-compress</artifactId> <version>${commons-compress.version}</version> </dependency> <!-- Jackson Json處理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <!-- quartz任務調度框架 --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>${quartz.version}</version> </dependency> <!-- 單元測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- 日誌處理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> <version>${mybatis.paginator.version}</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${pagehelper.version}</version> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- 鏈接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.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-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</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-context-support</artifactId> <version>${spring.version}</version> </dependency> <!-- JSP相關 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${servlet-api.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>${jsp-api.version}</version> <scope>provided</scope> </dependency> <!-- 文件上傳組件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload.version}</version> </dependency> <!-- Redis客戶端 --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${jedis.version}</version> </dependency> <!-- solr客戶端 --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>${solrj.version}</version> </dependency> <!-- dubbo相關 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> </dependency> <!-- zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>${zookeeper.version}</version> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>${zkclient.version}</version> </dependency> <!-- activemq --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>${activemq.version}</version> </dependency> <!-- freemarker --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>${freemarker.version}</version> </dependency> <!-- hutool工具類 很是好用 --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version> </dependency> <!-- 權限管理shiro --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-all</artifactId> <version>${shiro.version}</version> </dependency> <!-- mail郵件發送 --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>${mail.version}</version> </dependency> <!-- fastdfs客戶端 --> <dependency> <groupId>org.csource</groupId> <artifactId>fastdfs-client-java</artifactId> <version>${fastdfs.version}</version> </dependency> <!-- 二維碼工具 --> <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>${zxingcore.version}</version> </dependency> <!-- Beetl模板 --> <dependency> <groupId>com.ibeetl</groupId> <artifactId>beetl</artifactId> <version>${beetl.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <finalName>${project.artifactId}</finalName> <plugins> <!-- 資源文件拷貝插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- java編譯插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>sunda-parent</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <groupId>com.sundablog</groupId> <artifactId>sunda-common</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> <version>${oshi-core.version}</version> </dependency> <!-- 時間操做組件 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> </dependency> <!-- Apache工具組件 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-compress</artifactId> </dependency> <!-- Jackson Json處理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <!-- quartz任務調度框架 --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> </dependency> <!-- 單元測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- 日誌處理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!-- 工具類 --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> </dependency> <!-- fastdfs --> <dependency> <groupId>org.csource</groupId> <artifactId>fastdfs-client-java</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> </dependencies> </project>
package com.sundablog.fastdfs; import org.csource.common.NameValuePair; import org.csource.fastdfs.ClientGlobal; import org.csource.fastdfs.StorageClient1; import org.csource.fastdfs.StorageServer; import org.csource.fastdfs.TrackerClient; import org.csource.fastdfs.TrackerServer; /** * Fastdfs上傳接口類 * @ClassName: FastdfsClient * @Description:TODO(這裏用一句話描述這個類的做用) * @author: 噠噠 * @date: Nov 6, 2017 11:30:22 PM * * @Copyright: 2017 www.sundablog.com Inc. All rights reserved. */ public class FastdfsClient { private TrackerClient trackerClient = null; private TrackerServer trackerServer = null; private StorageServer storageServer = null; private StorageClient1 storageClient = null; private final String classpath = "classpath:"; public FastdfsClient(String conf) throws Exception { if (conf.contains(classpath)) { conf = conf.replace("classpath:", this.getClass().getResource("/").getPath()); } ClientGlobal.init(conf); trackerClient = new TrackerClient(); trackerServer = trackerClient.getConnection(); storageServer = null; storageClient = new StorageClient1(trackerServer, storageServer); } /** * 上傳文件方法 * <p>Title: uploadFile</p> * <p>Description: </p> * @param fileName 文件全路徑 * @param extName 文件擴展名,不包含(.) * @param metas 文件擴展信息 * @return * @throws Exception */ public String uploadFile(String fileName, String extName, NameValuePair[] metas) throws Exception { String result = storageClient.upload_file1(fileName, extName, metas); return result; } public String uploadFile(String fileName) throws Exception { return uploadFile(fileName, null, null); } public String uploadFile(String fileName, String extName) throws Exception { return uploadFile(fileName, extName, null); } /** * 上傳文件方法 * <p>Title: uploadFile</p> * <p>Description: </p> * @param fileContent 文件的內容,字節數組 * @param extName 文件擴展名 * @param metas 文件擴展信息 * @return * @throws Exception */ public String uploadFile(byte[] fileContent, String extName, NameValuePair[] metas) throws Exception { String result = storageClient.upload_file1(fileContent, extName, metas); return result; } public String uploadFile(byte[] fileContent) throws Exception { return uploadFile(fileContent, null, null); } public String uploadFile(byte[] fileContent, String extName) throws Exception { return uploadFile(fileContent, extName, null); } }
package com.sundablog.result; import java.util.List; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; /** * 統一返回結果類 * @ClassName: BaseResult * @Description:TODO(統一返回結果類) * @author: 噠噠 * @date: Oct 30, 2017 10:46:14 PM * * @Copyright: 2017 www.sundablog.com Inc. All rights reserved. */ public class BaseResult { /** 修改爲功 */ public static final String updataSuccess = "修改爲功"; /** 修改失敗 */ public static final String updataFail = "修改失敗"; /** 添加成功 */ public static final String addSuccess = "添加成功"; /** 添加失敗 */ public static final String addFail = "添加失敗"; /** 刪除成功 */ public static final String delectSuccess = "刪除成功"; /** 刪除失敗 */ public static final String delectFail = "刪除失敗"; /** 發送成功 */ public static final String sendSuccess = "發送成功"; /** 發送失敗 */ public static final String sendFail = "發送失敗"; /** 無數據 */ public static final String selectFail = "無數據"; /** * 定義jackson對象 */ private static final ObjectMapper MAPPER = new ObjectMapper(); /** * 響應業務狀態 */ private Integer status; /** * 響應消息 */ private String msg; /** * 響應中的數據 */ private Object data; public static BaseResult build(Integer status, String msg, Object data) { return new BaseResult(status, msg, data); } public static BaseResult ok(Object data) { return new BaseResult(data); } public static BaseResult ok() { return new BaseResult(null); } public BaseResult() { } public static BaseResult build(Integer status, String msg) { return new BaseResult(status, msg, null); } public BaseResult(Integer status, String msg, Object data) { this.status = status; this.msg = msg; this.data = data; } public BaseResult(Object data) { this.status = 200; this.msg = "OK"; this.data = data; } public Integer getStatus() { return status; } public void setStatus(Integer status) { this.status = status; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getData() { return data; } public void setData(Object data) { this.data = data; } /** * 將json結果集轉化爲BaseResult對象 * * @param jsonData json數據 * @param clazz BaseResult中的object類型 * @return */ public static BaseResult formatToPojo(String jsonData, Class<?> clazz) { try { if (clazz == null) { return MAPPER.readValue(jsonData, BaseResult.class); } JsonNode jsonNode = MAPPER.readTree(jsonData); JsonNode data = jsonNode.get("data"); Object obj = null; if (clazz != null) { if (data.isObject()) { obj = MAPPER.readValue(data.traverse(), clazz); } else if (data.isTextual()) { obj = MAPPER.readValue(data.asText(), clazz); } } return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj); } catch (Exception e) { return null; } } /** * 沒有object對象的轉化 * * @param json * @return */ public static BaseResult format(String json) { try { return MAPPER.readValue(json, BaseResult.class); } catch (Exception e) { e.printStackTrace(); } return null; } /** * Object是集合轉化 * a * @param jsonData json數據 * @param clazz 集合中的類型 * @return */ public static BaseResult formatToList(String jsonData, Class<?> clazz) { try { JsonNode jsonNode = MAPPER.readTree(jsonData); JsonNode data = jsonNode.get("data"); Object obj = null; if (data.isArray() && data.size() > 0) { obj = MAPPER.readValue(data.traverse(), MAPPER.getTypeFactory().constructCollectionType(List.class, clazz)); } return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj); } catch (Exception e) { return null; } } }
package com.sundablog.utlis; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; /** * AES加解密工具類 * @ClassName: AESUtil * @Description:AES加解密工具類 * @author: 噠噠 * @date: 2018年3月9日 下午5:55:23 * * @Copyright: 2018 www.sundablog.com Inc. All rights reserved. */ public class AESUtil { private static final String ENCODE_RULES = "zheng"; /** * 加密 * 1.構造密鑰生成器 * 2.根據ecnodeRules規則初始化密鑰生成器 * 3.產生密鑰 * 4.建立和初始化密碼器 * 5.內容加密 * 6.返回字符串 */ public static String aesEncode(String content) { try { //1.構造密鑰生成器,指定爲AES算法,不區分大小寫 KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); //2.根據ecnodeRules規則初始化密鑰生成器 //生成一個128位的隨機源,根據傳入的字節數組 SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(ENCODE_RULES.getBytes()); keyGenerator.init(128, random); //3.產生原始對稱密鑰 SecretKey originalKey = keyGenerator.generateKey(); //4.得到原始對稱密鑰的字節數組 byte[] raw = originalKey.getEncoded(); //5.根據字節數組生成AES密鑰 SecretKey key = new SecretKeySpec(raw, "AES"); //6.根據指定算法AES自成密碼器 Cipher cipher = Cipher.getInstance("AES"); //7.初始化密碼器,第一個參數爲加密(Encrypt_mode)或者解密解密(Decrypt_mode)操做,第二個參數爲使用的KEY cipher.init(Cipher.ENCRYPT_MODE, key); //8.獲取加密內容的字節數組(這裏要設置爲utf-8)否則內容中若是有中文和英文混合中文就會解密爲亂碼 byte[] byteEncode = content.getBytes("utf-8"); //9.根據密碼器的初始化方式--加密:將數據加密 byte[] byteAES = cipher.doFinal(byteEncode); //10.將加密後的數據轉換爲字符串 //這裏用Base64Encoder中會找不到包 //解決辦法: //在項目的Build path中先移除JRE System Library,再添加庫JRE System Library,從新編譯後就一切正常了。 String aesEncode = new String(new BASE64Encoder().encode(byteAES)); //11.將字符串返回 return aesEncode; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } //若是有錯就返加nulll return null; } /** * 解密 * 解密過程: * 1.同加密1-4步 * 2.將加密後的字符串反紡成byte[]數組 * 3.將加密內容解密 */ public static String aesDecode(String content) { try { //1.構造密鑰生成器,指定爲AES算法,不區分大小寫 KeyGenerator keygen = KeyGenerator.getInstance("AES"); //2.根據ecnodeRules規則初始化密鑰生成器 //生成一個128位的隨機源,根據傳入的字節數組 SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(ENCODE_RULES.getBytes()); keygen.init(128, random); //3.產生原始對稱密鑰 SecretKey originalKey = keygen.generateKey(); //4.得到原始對稱密鑰的字節數組 byte[] raw = originalKey.getEncoded(); //5.根據字節數組生成AES密鑰 SecretKey key = new SecretKeySpec(raw, "AES"); //6.根據指定算法AES自成密碼器 Cipher cipher = Cipher.getInstance("AES"); //7.初始化密碼器,第一個參數爲加密(Encrypt_mode)或者解密(Decrypt_mode)操做,第二個參數爲使用的KEY cipher.init(Cipher.DECRYPT_MODE, key); //8.將加密並編碼後的內容解碼成字節數組 byte[] byteContent = new BASE64Decoder().decodeBuffer(content); /* * 解密 */ byte[] byteDecode = cipher.doFinal(byteContent); String aesDecode = new String(byteDecode, "utf-8"); return aesDecode; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { throw new RuntimeException("兄弟,配置文件中的密碼須要使用AES加密,請使用com.zheng.common.util.AESUtil工具類修改這些值!"); //e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } //若是有錯就返加nulll return null; } public static void main(String[] args) { String[] keys = { "", "123456" }; System.out.println("key | AESEncode | AESDecode"); for (String key : keys) { System.out.print(key + " | "); String encryptString = aesEncode(key); System.out.print(encryptString + " | "); String decryptString = aesDecode(encryptString); System.out.println(decryptString); } } }
package com.sundablog.utlis; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; import java.util.Random; /** * 驗證碼工具類 * @ClassName: CaptchaUtil * @Description:TODO(驗證碼工具類) * @author: 噠噠 * @date: Oct 30, 2017 7:04:39 PM * * @Copyright: 2017 www.sundablog.com Inc. All rights reserved. */ public class CaptchaUtil { // 圖片的寬度。 private int width = 160; // 圖片的高度。 private int height = 40; // 驗證碼字符個數 private int codeCount = 4; // 驗證碼干擾線數 private int lineCount = 20; // 驗證碼 private String code = null; // 驗證碼圖片Buffer private BufferedImage buffImg = null; Random random = new Random(); public CaptchaUtil() { creatImage(); } public CaptchaUtil(int width, int height) { this.width = width; this.height = height; creatImage(); } public CaptchaUtil(int width, int height, int codeCount) { this.width = width; this.height = height; this.codeCount = codeCount; creatImage(); } public CaptchaUtil(int width, int height, int codeCount, int lineCount) { this.width = width; this.height = height; this.codeCount = codeCount; this.lineCount = lineCount; creatImage(); } // 生成圖片 private void creatImage() { int fontWidth = width / codeCount;// 字體的寬度 int fontHeight = height - 5;// 字體的高度 int codeY = height - 8; // 圖像buffer buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = buffImg.getGraphics(); //Graphics2D g = buffImg.createGraphics(); // 設置背景色 g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); // 設置字體 //Font font1 = getFont(fontHeight); Font font = new Font("Fixedsys", Font.BOLD, fontHeight); g.setFont(font); // 設置干擾線 for (int i = 0; i < lineCount; i++) { int xs = random.nextInt(width); int ys = random.nextInt(height); int xe = xs + random.nextInt(width); int ye = ys + random.nextInt(height); g.setColor(getRandColor(1, 255)); g.drawLine(xs, ys, xe, ye); } // 添加噪點 float yawpRate = 0.01f;// 噪聲率 int area = (int) (yawpRate * width * height); for (int i = 0; i < area; i++) { int x = random.nextInt(width); int y = random.nextInt(height); buffImg.setRGB(x, y, random.nextInt(255)); } String str1 = randomStr(codeCount);// 獲得隨機字符 this.code = str1; for (int i = 0; i < codeCount; i++) { String strRand = str1.substring(i, i + 1); g.setColor(getRandColor(1, 255)); // g.drawString(a,x,y); // a爲要畫出來的東西,x和y表示要畫的東西最左側字符的基線位於此圖形上下文座標系的 (x, y) 位置處 g.drawString(strRand, i * fontWidth + 3, codeY); } } // 獲得隨機字符 private String randomStr(int n) { String str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; String str2 = ""; int len = str1.length() - 1; double r; for (int i = 0; i < n; i++) { r = (Math.random()) * len; str2 = str2 + str1.charAt((int) r); } return str2; } // 獲得隨機顏色 private Color getRandColor(int fc, int bc) {// 給定範圍得到隨機顏色 if (fc > 255) fc = 255; if (bc > 255) bc = 255; int r = fc + random.nextInt(bc - fc); int g = fc + random.nextInt(bc - fc); int b = fc + random.nextInt(bc - fc); return new Color(r, g, b); } /** * 產生隨機字體 */ private Font getFont(int size) { Random random = new Random(); Font font[] = new Font[5]; font[0] = new Font("Ravie", Font.PLAIN, size); font[1] = new Font("Antique Olive Compact", Font.PLAIN, size); font[2] = new Font("Fixedsys", Font.PLAIN, size); font[3] = new Font("Wide Latin", Font.PLAIN, size); font[4] = new Font("Gill Sans Ultra Bold", Font.PLAIN, size); return font[random.nextInt(5)]; } // 扭曲方法 private void shear(Graphics g, int w1, int h1, Color color) { shearX(g, w1, h1, color); shearY(g, w1, h1, color); } private void shearX(Graphics g, int w1, int h1, Color color) { int period = random.nextInt(2); boolean borderGap = true; int frames = 1; int phase = random.nextInt(2); for (int i = 0; i < h1; i++) { double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames); g.copyArea(0, i, w1, 1, (int) d, 0); if (borderGap) { g.setColor(color); g.drawLine((int) d, i, 0, i); g.drawLine((int) d + w1, i, w1, i); } } } private void shearY(Graphics g, int w1, int h1, Color color) { int period = random.nextInt(40) + 10; // 50; boolean borderGap = true; int frames = 20; int phase = 7; for (int i = 0; i < w1; i++) { double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames); g.copyArea(i, 0, 1, h1, 0, (int) d); if (borderGap) { g.setColor(color); g.drawLine(i, (int) d, i, 0); g.drawLine(i, (int) d + h1, i, h1); } } } public void write(OutputStream sos) throws IOException { ImageIO.write(buffImg, "png", sos); sos.close(); } public BufferedImage getBuffImg() { return buffImg; } public String getCode() { return code.toLowerCase(); } // /** // * 驗證碼 // * @param request // * @param response // * @param session // * @throws IOException // */ // @RequestMapping("/code.jpg") // public void getCode3(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException { // int width = NumberUtils.toInt(request.getParameter("width"), 100); // int height = NumberUtils.toInt(request.getParameter("height"), 30); // int codeCount = NumberUtils.toInt(request.getParameter("codeCount"), 4); // int lineCount = NumberUtils.toInt(request.getParameter("lineCount"), 10); // if (width > 1000) width = 100; // if (height > 300) height = 30; // if (codeCount > 10) codeCount = 4; // if (lineCount > 100) lineCount = 10; // // 設置響應的類型格式爲圖片格式 // response.setContentType("image/jpeg"); // // 禁止圖像緩存。 // response.setHeader("Pragma", "no-cache"); // response.setHeader("Cache-Control", "no-cache"); // response.setDateHeader("Expires", 0); // // 自定義參數 // CaptchaUtil code = new CaptchaUtil(width, height, codeCount, lineCount); // String sessionId = session.getId(); // RedisUtil.set("captcha_" + sessionId, code.getCode(), 60 * 30); // code.write(response.getOutputStream()); // } }
package com.sundablog.utlis; import java.util.Date; import java.util.HashMap; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * 資源文件讀取工具 * @ClassName: PropertiesFileUtil * @Description:TODO(這裏用一句話描述這個類的做用) * @author: 噠噠 * @date: 2018年3月2日 上午10:33:00 * * @Copyright: 2018 www.sundablog.com Inc. All rights reserved. */ public class PropertiesFileUtil { // 當打開多個資源文件時,緩存資源文件 private static HashMap<String, PropertiesFileUtil> configMap = new HashMap<String, PropertiesFileUtil>(); // 打開文件時間,判斷超時使用 private Date loadTime = null; // 資源文件 private ResourceBundle resourceBundle = null; // 默認資源文件名稱 private static final String NAME = "config"; // 緩存時間 private static final Integer TIME_OUT = 60 * 1000; // 私有構造方法,建立單例 private PropertiesFileUtil(String name) { this.loadTime = new Date(); this.resourceBundle = ResourceBundle.getBundle(name); } public static synchronized PropertiesFileUtil getInstance() { return getInstance(NAME); } public static synchronized PropertiesFileUtil getInstance(String name) { PropertiesFileUtil conf = configMap.get(name); if (null == conf) { conf = new PropertiesFileUtil(name); configMap.put(name, conf); } // 判斷是否打開的資源文件是否超時1分鐘 if ((System.currentTimeMillis() - conf.getLoadTime().getTime()) > TIME_OUT) { conf = new PropertiesFileUtil(name); configMap.put(name, conf); } return conf; } // 根據key讀取value public String get(String key) { try { String value = resourceBundle.getString(key); return value; } catch (MissingResourceException e) { return ""; } } // 根據key讀取value(整形) public Integer getInt(String key) { try { String value = resourceBundle.getString(key); return Integer.parseInt(value); } catch (MissingResourceException e) { return null; } } // 根據key讀取value(布爾) public boolean getBool(String key) { try { String value = resourceBundle.getString(key); if ("true".equals(value)) { return true; } return false; } catch (MissingResourceException e) { return false; } } public Date getLoadTime() { return loadTime; } }
package com.sundablog.utlis; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import java.util.concurrent.locks.ReentrantLock; /** * Redis 工具類 * @ClassName: RedisUtil * @Description:TODO(這裏用一句話描述這個類的做用) * @author: 噠噠 * @date: 2018年3月2日 上午10:33:27 * * @Copyright: 2018 www.sundablog.com Inc. All rights reserved. */ public class RedisUtil { protected static ReentrantLock lockPool = new ReentrantLock(); protected static ReentrantLock lockJedis = new ReentrantLock(); private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtil.class); // Redis服務器IP private static String IP = PropertiesFileUtil.getInstance("redis").get("master.redis.ip"); // Redis的端口號 private static int PORT = PropertiesFileUtil.getInstance("redis").getInt("master.redis.port"); // 訪問密碼 private static String PASSWORD = AESUtil.aesDecode(PropertiesFileUtil.getInstance("redis").get("master.redis.password")); // 可用鏈接實例的最大數目,默認值爲8; // 若是賦值爲-1,則表示不限制;若是pool已經分配了maxActive個jedis實例,則此時pool的狀態爲exhausted(耗盡)。 private static int MAX_ACTIVE = PropertiesFileUtil.getInstance("redis").getInt("master.redis.max_active"); // 控制一個pool最多有多少個狀態爲idle(空閒的)的jedis實例,默認值也是8。 private static int MAX_IDLE = PropertiesFileUtil.getInstance("redis").getInt("master.redis.max_idle"); // 等待可用鏈接的最大時間,單位毫秒,默認值爲-1,表示永不超時。若是超過等待時間,則直接拋出JedisConnectionException; private static int MAX_WAIT = PropertiesFileUtil.getInstance("redis").getInt("master.redis.max_wait"); // 超時時間 private static int TIMEOUT = PropertiesFileUtil.getInstance("redis").getInt("master.redis.timeout"); // 在borrow一個jedis實例時,是否提早進行validate操做;若是爲true,則獲得的jedis實例均是可用的; private static boolean TEST_ON_BORROW = false; private static JedisPool jedisPool = null; /** * redis過時時間,以秒爲單位 */ // 一小時 public final static int EXRP_HOUR = 60 * 60; // 一天 public final static int EXRP_DAY = 60 * 60 * 24; // 一個月 public final static int EXRP_MONTH = 60 * 60 * 24 * 30; /** * 初始化Redis鏈接池 */ private static void initialPool() { try { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(MAX_ACTIVE); config.setMaxIdle(MAX_IDLE); config.setMaxWaitMillis(MAX_WAIT); config.setTestOnBorrow(TEST_ON_BORROW); jedisPool = new JedisPool(config, IP, PORT, TIMEOUT); } catch (Exception e) { LOGGER.error("First create JedisPool error : " + e); } } /** * 在多線程環境同步初始化 */ private static synchronized void poolInit() { if (null == jedisPool) { initialPool(); } } /** * 同步獲取Jedis實例 * @return Jedis */ public synchronized static Jedis getJedis() { poolInit(); Jedis jedis = null; try { if (null != jedisPool) { jedis = jedisPool.getResource(); try { jedis.auth(PASSWORD); } catch (Exception e) { } } } catch (Exception e) { LOGGER.error("Get jedis error : " + e); } return jedis; } /** * 設置 String * @param key * @param value */ public synchronized static void set(String key, String value) { try { value = StringUtils.isBlank(value) ? "" : value; Jedis jedis = getJedis(); jedis.set(key, value); jedis.close(); } catch (Exception e) { LOGGER.error("Set key error : " + e); } } /** * 設置 byte[] * @param key * @param value */ public synchronized static void set(byte[] key, byte[] value) { try { Jedis jedis = getJedis(); jedis.set(key, value); jedis.close(); } catch (Exception e) { LOGGER.error("Set key error : " + e); } } /** * 設置 String 過時時間 * @param key * @param value * @param seconds 以秒爲單位 */ public synchronized static void set(String key, String value, int seconds) { try { value = StringUtils.isBlank(value) ? "" : value; Jedis jedis = getJedis(); jedis.setex(key, seconds, value); jedis.close(); } catch (Exception e) { LOGGER.error("Set keyex error : " + e); } } /** * 設置 byte[] 過時時間 * @param key * @param value * @param seconds 以秒爲單位 */ public synchronized static void set(byte[] key, byte[] value, int seconds) { try { Jedis jedis = getJedis(); jedis.set(key, value); jedis.expire(key, seconds); jedis.close(); } catch (Exception e) { LOGGER.error("Set key error : " + e); } } /** * 獲取String值 * @param key * @return value */ public synchronized static String get(String key) { Jedis jedis = getJedis(); if (null == jedis) { return null; } String value = jedis.get(key); jedis.close(); return value; } /** * 獲取byte[]值 * @param key * @return value */ public synchronized static byte[] get(byte[] key) { Jedis jedis = getJedis(); if (null == jedis) { return null; } byte[] value = jedis.get(key); jedis.close(); return value; } /** * 刪除值 * @param key */ public synchronized static void remove(String key) { try { Jedis jedis = getJedis(); jedis.del(key); jedis.close(); } catch (Exception e) { LOGGER.error("Remove keyex error : " + e); } } /** * 刪除值 * @param key */ public synchronized static void remove(byte[] key) { try { Jedis jedis = getJedis(); jedis.del(key); jedis.close(); } catch (Exception e) { LOGGER.error("Remove keyex error : " + e); } } /** * lpush * @param key * @param key */ public synchronized static void lpush(String key, String... strings) { try { Jedis jedis = RedisUtil.getJedis(); jedis.lpush(key, strings); jedis.close(); } catch (Exception e) { LOGGER.error("lpush error : " + e); } } /** * lrem * @param key * @param count * @param value */ public synchronized static void lrem(String key, long count, String value) { try { Jedis jedis = RedisUtil.getJedis(); jedis.lrem(key, count, value); jedis.close(); } catch (Exception e) { LOGGER.error("lpush error : " + e); } } /** * sadd * @param key * @param value * @param seconds */ public synchronized static void sadd(String key, String value, int seconds) { try { Jedis jedis = RedisUtil.getJedis(); jedis.sadd(key, value); jedis.expire(key, seconds); jedis.close(); } catch (Exception e) { LOGGER.error("sadd error : " + e); } } /** * incr * @param key * @return value */ public synchronized static Long incr(String key) { Jedis jedis = getJedis(); if (null == jedis) { return null; } long value = jedis.incr(key); jedis.close(); return value; } /** * decr * @param key * @return value */ public synchronized static Long decr(String key) { Jedis jedis = getJedis(); if (null == jedis) { return null; } long value = jedis.decr(key); jedis.close(); return value; } }
package com.sundablog.utlis; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import oshi.SystemInfo; import oshi.hardware.CentralProcessor; import oshi.hardware.CentralProcessor.TickType; import oshi.hardware.GlobalMemory; import oshi.hardware.HardwareAbstractionLayer; import oshi.util.FormatUtil; import oshi.util.Util; /** * Java系統監控測試類 * * @ClassName: SystemInfoTest * @Description:TODO(這裏用一句話描述這個類的做用) * @author: 噠噠 * @date: 2018年3月1日 下午5:33:51 * * @Copyright: 2018 www.sundablog.com Inc. All rights reserved. */ public class SystemUtils { /** * 獲取系統內存 * @Title: Memory * @Description: TODO(這裏用一句話描述這個方法的做用) * @param: @param memory * @param: @return * @return: Map<String,String> * @throws */ public static Map<String, String> Memory(GlobalMemory memory) { long available = memory.getAvailable(); long total = memory.getTotal(); double aa = (available / (double) total) * 100; int percentage = (int) aa; Map<String, String> map = new HashMap<>(); map.put("available", FormatUtil.formatBytes(memory.getAvailable())); map.put("total", FormatUtil.formatBytes(memory.getTotal())); map.put("Percentage", String.valueOf(percentage)); return map; } /** * 獲取系統cpu百分百 * @Title: Cpu * @Description: TODO(這裏用一句話描述這個方法的做用) * @param: @param processor * @param: @return * @return: int * @throws */ public static int Cpu(CentralProcessor processor) { Util.sleep(1000); return (int) (processor.getSystemCpuLoadBetweenTicks() * 100); } }
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>sunda-parent</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <groupId>com.sundablog</groupId> <artifactId>backend</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <dependencies> <dependency> <groupId>com.sundablog</groupId> <artifactId>sunda-common</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> <modules> <module>backend-server-pojo</module> <module>backend-server-dao</module> <module>backend-server-interface</module> <module>backend-server-rpc</module> <module>backend-server-web</module> </modules> </project>
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>backend</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>backend-server-pojo</artifactId> </project>
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>backend</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>backend-server-dao</artifactId> <dependencies> <dependency> <groupId>com.sundablog</groupId> <artifactId>backend-server-pojo</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <!-- 添加對mybatis的依賴 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 鏈接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> </dependencies> <!-- 若是不添加此節點mybatis的mapper.xml文件都會被漏掉。 --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build> </project>
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>backend</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>backend-server-interface</artifactId> <dependencies> <dependency> <groupId>com.sundablog</groupId> <artifactId>backend-server-pojo</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> </project>
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>backend</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>backend-server-rpc</artifactId> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.sundablog</groupId> <artifactId>backend-server-dao</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.sundablog</groupId> <artifactId>backend-server-interface</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- shiro --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-all</artifactId> </dependency> <!-- dubbo相關 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> </dependency> <!-- fastdfs客戶端 --> <dependency> <groupId>org.csource</groupId> <artifactId>fastdfs-client-java</artifactId> </dependency> </dependencies> <!-- 配置Tomcat的插件 --> <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <path>/</path> <port>9990</port> </configuration> </plugin> </plugins> </build> </project>
<?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>backend-server-rpc</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- 加載spring容器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--阿里druid --> <filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> <init-param> <param-name>exclusions</param-name> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value> </init-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> <!-- 數據庫鏈接池 --> <!-- 加載配置文件 --> <context:property-placeholder location="classpath:config/*.properties" /> <!-- 數據庫鏈接池 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="driverClassName" value="${jdbc.driver}" /> <property name="filters" value="${jdbc.filters}" /> <!-- 最大併發鏈接數 --> <property name="maxActive" value="${jdbc.maxActive}" /> <!-- 初始化鏈接數量 --> <property name="initialSize" value="${jdbc.initialSize}" /> <!-- 配置獲取鏈接等待超時的時間 --> <property name="maxWait" value="${jdbc.maxWait}" /> <!-- 最小空閒鏈接數 --> <property name="minIdle" value="${jdbc.minIdle}" /> <!-- 配置間隔多久才進行一次檢測,檢測須要關閉的空閒鏈接,單位是毫秒 --> <!-- 官方說明:有兩個含義: 1) Destroy線程會檢測鏈接的間隔時間2) testWhileIdle的判斷依據,詳細看testWhileIdle屬性的說明 --> <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" /> <!-- 配置一個鏈接在池中最小生存的時間,單位是毫秒 --> <!-- 官方無說明 --> <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" /> <!-- 官方說明:用來檢測鏈接是否有效的sql,要求是一個查詢語句。若是validationQuery爲null,testOnBorrow、testOnReturn、testWhileIdle都不會其做用。 --> <property name="validationQuery" value="${jdbc.validationQuery}" /> <!-- 官方說明:建議配置爲true,不影響性能,而且保證安全性。申請鏈接的時候檢測,若是空閒時間大於timeBetweenEvictionRunsMillis,執行validationQuery檢測鏈接是否有效。 --> <property name="testWhileIdle" value="${jdbc.testWhileIdle}" /> <!-- 官方說明:申請鏈接時執行validationQuery檢測鏈接是否有效,作了這個配置會下降性能。 --> <property name="testOnBorrow" value="${jdbc.testOnBorrow}" /> <!-- 官方說明:歸還鏈接時執行validationQuery檢測鏈接是否有效,作了這個配置會下降性能 --> <property name="testOnReturn" value="${jdbc.testOnReturn}" /> <!-- 官方說明:要啓用PSCache,必須配置大於0,當大於0時,poolPreparedStatements自動觸發修改成true。在Druid中,不會存在Oracle下PSCache佔用內存過多的問題,能夠把這個數值配置大一些,好比說100 --> <property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}" /> <!-- 打開 removeAbandoned 功能,超過期間限制是否回收 --> <property name="removeAbandoned" value="${jdbc.removeAbandoned}" /> <!-- 1800 秒,也就是 30 分鐘 --> <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" /> <!-- 關閉 abanded 鏈接時輸出錯誤日誌 --> <property name="logAbandoned" value="${jdbc.logAbandoned}" /> </bean> <!-- 讓spring管理sqlsessionfactory 使用mybatis和spring整合包中的 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 數據庫鏈接池 --> <property name="dataSource" ref="dataSource" /> <!-- 加載mybatis的全局配置文件 --> <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.sundablog.mapper" /> </bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <context:component-scan base-package="com.sundablog.service"/> <!-- 使用dubbo發佈服務 --> <!-- 提供方應用信息,用於計算依賴關係 --> <dubbo:application name="backend-server-rpc" /> <dubbo:registry protocol="zookeeper" address="120.77.159.227:2181" /> <!-- 用dubbo協議在20880端口暴露服務 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 聲明須要暴露的服務接口 --> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- 事務管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 數據源 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- 傳播行爲 --> <!-- 保存 --> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <!-- 刪除 基本用不到 --> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <!-- 修改 --> <tx:method name="update*" propagation="REQUIRED" /> <!-- 查詢 --> <!-- 獲取單個 --> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> <!-- 獲取多個 --> <tx:method name="list*" propagation="SUPPORTS" read-only="true" /> <tx:method name="find*" propagation="SUPPORTS" read-only="true" /> <!-- 獲取統計 --> <tx:method name="count*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- 切面 --> <aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.sundablog.service..*.*(..))" /> </aop:config> </beans>
<?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> <plugins> <!-- com.github.pagehelper爲PageHelper類所在包名 --> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 設置數據庫類型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種數據庫 --> <property name="dialect" value="mysql" /> </plugin> </plugins> </configuration>
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8 jdbc.username=sunda jdbc.password=1314520abc! jdbc.filters=stat jdbc.maxActive=20 jdbc.initialSize=1 jdbc.maxWait=60000 jdbc.minIdle=10 jdbc.timeBetweenEvictionRunsMillis=60000 jdbc.minEvictableIdleTimeMillis=300000 jdbc.validationQuery=SELECT 'x' jdbc.testWhileIdle=true jdbc.testOnBorrow=false jdbc.testOnReturn=false jdbc.maxOpenPreparedStatements=20 jdbc.removeAbandoned=true jdbc.removeAbandonedTimeout=1800 jdbc.logAbandoned=true
#fastdfs服務器地址 tracker_server=192.168.2.234:22122
# 郵件服務器的SMTP地址,可選,默認爲smtp.<發件人郵箱後綴> host = smtp.163.com # 郵件服務器的SMTP端口,可選,默認25 port = 25 # 是否用戶名密碼驗證 auth = true # 發件人(必須正確,不然發送失敗) from = # 用戶名,默認爲發件人郵箱前綴 user = # 密碼(注意,某些郵箱須要爲SMTP服務單獨設置密碼,詳情查看相關幫助) pass = #使用SSL加密方式發送郵件 在使用QQ或Gmail郵箱時,須要強制開啓SSL支持,此時咱們只需修改配置文件便可: #使用 STARTTLS安全鏈接 startttlsEnable = true # 指定實現javax.net.SocketFactory接口的類的名稱,這個類將被用於建立SMTP的套接字 socketFactoryClass = javax.net.ssl.SSLSocketFactory # 若是設置爲true,未能建立一個套接字使用指定的套接字工廠類將致使使用java.net.Socket建立的套接字類, 默認值爲true socketFactoryFallback = true # 指定的端口鏈接到在使用指定的套接字工廠。若是沒有設置,將使用默認端口456 socketFactoryPort = 465
#fastdfs圖片服務器地址 IMAGE_SERVER_URL=http://192.168.2.234/
<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> <parent> <groupId>com.sundablog</groupId> <artifactId>backend</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>backend-server-web</artifactId> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.sundablog</groupId> <artifactId>backend-server-interface</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <scope>provided</scope> </dependency> <!-- 文件上傳組件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> <!-- dubbo相關 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> </exclusion> </exclusions> </dependency> <!-- shiro --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-all</artifactId> </dependency> <!-- zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> </dependency> <!-- 文件上傳組件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> </dependencies> <build> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <path>/</path> <port>8080</port> </configuration> </plugin> </plugins> </build> </project>
<?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>backend-server-web</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- 解決post亂碼 --> <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> <!-- 加載配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-*.xml,classpath:spring/springmvc.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- springmvc的前端控制器 --> <servlet> <servlet-name>CMS</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CMS</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.sundablog.controller" /> <mvc:annotation-driven /> <aop:aspectj-autoproxy proxy-target-class="true" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 資源 --> <mvc:resources location="/LarryMS/" mapping="/LarryMS/**"></mvc:resources> <!-- 配置多媒體編輯器 --> <!-- 定義文件上傳解析器 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 設定默認編碼 --> <property name="defaultEncoding" value="UTF-8"></property> <!-- 設定文件上傳的最大值5MB,5*1024*1024 --> <property name="maxUploadSize" value="5242880"></property> </bean> </beans>
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 引用dubbo服務 --> <dubbo:application name="backend-server-web" /> <dubbo:registry protocol="zookeeper" address="192.168.1.1:2181" /> </beans>