#
有非常非常多的 jQuery 插件,這些插件可以簡化你的 Web 應用開發。今天我們向你推薦 15 個用于布局和 UI 增強的 jQuery 插件。
Superscrollorama

jQuery File Upload Demo

jQuery Knob

jQuery Complexify

rcarousel

turn.js

jQuery HiddenPosition

Fancy Input

pickadate.js

Cool Kitten

stellar.js

windows

Infinite Scrolling

Autobrowse jQuery Infinite scrolling plugin using Ajax

jScrollPane

如果有人問你,作為一個軟件架構師需要哪些特質的話,你會怎么回答?從技術層面上講,架構師的技術要求是首位的。除此之外在做人處事方面,更有魅力的架構師則更受歡迎。 最近有個同事問我,是什么成就了一個架構師。下文就是我的回答,適用于各個技術領域。其中我故意不考慮企業架構相關的問題。 1、了解相關領域的技術知識 在你想要成為架構師的相關技術領域,必須具備扎實的專業知識和過人的本領。 2、超強的分析、設計能力 不管怎樣,具備很強的分析和設計能力都是必殺技。另外就是能夠運用設計模式方式解決各種各樣的問題。 3、編碼與驗證性測試(POC) 熟悉該組織整個技術棧,并能使用各層的技術熟練地編碼。 能快速實現驗證性測試。 4、架構設計的實力 能為原始需求提供架構方案。 考慮周全:工具和框架的采用、安全性、性能和擴展性、依賴關系、集成、效益。 熟悉軟件開發生命周期(SDLC):需求、分析、設計、測試、打包、部署。 5、建模語言或工具 能使用不同的建模語言或工具,向其他架構師、開發者、項目經理等人,闡述架構。 6、架構框架 能證明架構的可行性,包括其業務、應用、數據、基礎設置方面。 了解TOGAF和ZACHMAN框架就更好了。 7、溝通能力 能與開發人員、測試人員、商業分析師、上級經理溝通無阻,無論在口頭上和書面上。 8、布道 能講解該行業的市場、技術知識。 能為全隊提供培訓課程。 9、銷售、甚至售前 能參與售前工作(尤其對于軟件服務業):制定技術方案、使用各種預算工具估計方案的規模和成本、與銷售對象互動。 10、演講技巧 優秀的演講技巧,有助于以下活動:華麗的計劃書和技術文檔、PPT演講、布道。
在pom.xml中加入JAR包
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
ZipUtil.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ZipUtil {
private static Logger logger = LoggerFactory.getLogger(ZipUtil.class);
public static void extractFolder(InputStream inputStream, String outputFolder) throws IOException
{
ZipInputStream zis = null;
try {
Charset GBK = Charset.forName("GBK");
zis = new ZipInputStream(inputStream, GBK);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
// Create a file on HDD in the destinationPath directory
// destinationPath is a "root" folder, where you want to extract your ZIP file
String encoding = System.getProperty("file.encoding");
logger.info("encoding:"+encoding);
String fileName = new String(entry.getName().getBytes("GBK"), encoding);
File entryFile = new File(outputFolder, fileName);
// File entryFile = new File(outputFolder, entry.getName());
if (entry.isDirectory()) {
if (entryFile.exists()) {
logger.warn("Directory {0} already exists!", entryFile);
} else {
entryFile.mkdirs();
}
} else {
// Make sure all folders exists (they should, but the safer, the better ;-))
if (entryFile.getParentFile() != null && !entryFile.getParentFile().exists()) {
entryFile.getParentFile().mkdirs();
}
// Create file on disk
if (!entryFile.exists()) {
entryFile.createNewFile();
}
// and rewrite data from stream
OutputStream os = null;
try {
os = new FileOutputStream(entryFile);
IOUtils.copy(zis, os);
} finally {
// os.close();
IOUtils.closeQuietly(os);
zis.closeEntry();
}
}
}
} finally {
IOUtils.closeQuietly(zis);
}
}
public static void main(String [] args) throws IOException
{
final String INPUT_ZIP_FILE = "D:TESTING-FILE/ZIP/INPUT/應用.zip";
String OUTPUT_FOLDER = "D:/TESTING-FILE/ZIP/OUTPUT";
OUTPUT_FOLDER += File.separator + UUID.randomUUID().toString();
InputStream inputStream = new FileInputStream(new File(INPUT_ZIP_FILE));
extractFolder(inputStream, OUTPUT_FOLDER);
/*File file = new File(OUTPUT_FOLDER);
FileUtil.deleteFolder(file);*/
}
}
pom.xml回入以下包:
<dependency>
<groupId>net.sf.jxls</groupId>
<artifactId>jxls-core</artifactId>
</dependency>
<dependency>
<groupId>net.sf.jxls</groupId>
<artifactId>jxls-reader</artifactId>
</dependency>
<dependency>
<groupId>net.sf.jxls</groupId>
<artifactId>jxls-examples</artifactId>
</dependency>
轉換的配置文件:
<workbook>
<worksheet name="Sheet1">
<section startRow="0" endRow="0" />
<loop startRow="1" endRow="1" items="result" var="app" varType="n.app.valueobject.App">
<section startRow="1" endRow="1">
<mapping row="1" col="0">app.title</mapping>
<mapping row="1" col="1">app.categoryId</mapping>
<mapping row="1" col="2">app.updateContent</mapping>
<mapping row="1" col="3">app.rank</mapping>
<mapping row="1" col="4">app.installedQty</mapping>
<mapping row="1" col="5">app.installedType</mapping>
<mapping row="1" col="6">app.discuss</mapping>
<mapping row="1" col="7">app.summary</mapping>
<mapping row="1" col="8">app.deviceTypes</mapping>
<mapping row="1" col="9">app.description</mapping>
<mapping row="1" col="10">app.newFeatures</mapping>
<mapping row="1" col="11">app.shortRecommend</mapping>
<mapping row="1" col="12">app.appUrl</mapping>
</section>
<loopbreakcondition>
<rowcheck offset="0">
<cellcheck offset="0" />
</rowcheck>
</loopbreakcondition>
</loop>
</worksheet>
</workbook>
JAVA代碼:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jxls.reader.ReaderBuilder;
import net.sf.jxls.reader.XLSReader;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import application.app.valueobject.App;
public class ExcelUtil<T> {
private static Logger logger = LoggerFactory.getLogger(ExcelUtil.class);
public List<T> parseExcelFileToBeans(InputStream xlsFileInputStream, InputStream jxlsConfigInputStream) throws IOException, SAXException, InvalidFormatException {
List<T> result = new ArrayList<T>();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("result", result);
InputStream inputStream = null;
try {
XLSReader xlsReader = ReaderBuilder.buildFromXML(jxlsConfigInputStream);
inputStream = new BufferedInputStream(xlsFileInputStream);
xlsReader.read(inputStream, beans);
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw e;
} catch (SAXException e) {
logger.error(e.getMessage(), e);
throw e;
} catch (InvalidFormatException e) {
logger.error(e.getMessage(), e);
throw e;
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e) {
}
}
}
return result;
}
public static void main(String[] args) throws Exception {
String path = "D:/DATA/TESTING-FILE/EXCEL";
path = System.getProperty("user.home");
ExcelUtil<App> util = new ExcelUtil<App>();
String excelFilePath = path + File.separator + "appData.xls";
InputStream configInputStream =
ExcelUtil.class.getResourceAsStream("/excel/template/config/app_config.xml");
InputStream xlsFileInputStream = new FileInputStream(excelFilePath);
List<App> appList = util.parseExcelFileToBeans(xlsFileInputStream, configInputStream);
for (App app : appList) {
System.out.println(app.toString());
}
/*String [] args2 = {""};
GroupingSample.main(args2);*/
}
}
http://www.yihaomen.com/article/java/530.htm
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* <一句話功能簡述>
* <功能詳細描述>
*
* @author Administrator
* @version [版本號, 2014年3月7日]
* @see [相關類/方法]
* @since [產品/模塊版本]
*/
@Component
@Scope("prototype")
@RequestMapping("/downloadFile")
public class DownloadAction
{
@RequestMapping("download")
public ResponseEntity<byte[]> download() throws IOException {
String path="D:\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\springMVC\\WEB-INF\\upload\\圖片10(定價后).xlsx";
File file=new File(path);
HttpHeaders headers = new HttpHeaders();
String fileName=new String("你好.xlsx".getBytes("UTF-8"),"iso-8859-1");//為了解決中文名稱亂碼問題
headers.setContentDispositionFormData("attachment", fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}
}
JSP
<a href="./downloadFile/download" >下載</a>
https://github.com/spring-projects/spring-sync-samples/tree/master/spring-rest-todos
package todos;
import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Roy Clarkson
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = Application.class)
@Ignore
public class MainControllerTest {
@Autowired
private WebApplicationContext context;
@Mock
private TodoRepository repository;
@InjectMocks
TodoController mainController;
private MockMvc mvc;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mvc = MockMvcBuilders.standaloneSetup(mainController).build();
}
@Test
public void testList() throws Exception {
final Todo a = new Todo(1L, "a", false);
final Todo b = new Todo(2L, "b", false);
final Todo c = new Todo(3L, "c", false);
when(repository.findAll()).thenReturn(Arrays.asList(a, b, c));
mvc.perform(get("/todos")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(3)))
.andExpect(jsonPath("$[0].id", is(1)))
.andExpect(jsonPath("$[0].description", is("a")))
.andExpect(jsonPath("$[0].complete", is(false)))
.andExpect(jsonPath("$[1].id", is(2)))
.andExpect(jsonPath("$[1].description", is("b")))
.andExpect(jsonPath("$[1].complete", is(false)))
.andExpect(jsonPath("$[2].id", is(3)))
.andExpect(jsonPath("$[2].description", is("c")))
.andExpect(jsonPath("$[2].complete", is(false)));
verify(repository, times(1)).findAll();
verifyNoMoreInteractions(repository);
}
@Ignore
@Test
public void testPatch() throws Exception {
}
@Test
public void testCreate() throws Exception {
final Todo todo = new Todo(1L, "a", false);
ObjectMapper objectMapper = new ObjectMapper();
final byte[] bytes = objectMapper.writeValueAsBytes(todo);
when(repository.save(Mockito.any(Todo.class))).thenReturn(todo);
mvc.perform(post("/todos")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(bytes))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(1)))
.andExpect(jsonPath("$.description", is("a")))
.andExpect(jsonPath("$.complete", is(false)));
verify(repository, times(1)).save(Mockito.any(Todo.class));
verifyNoMoreInteractions(repository);
}
@Test
public void testUpdateSameIds() throws Exception {
final Todo updatedTodo = new Todo(1L, "z", true);
ObjectMapper objectMapper = new ObjectMapper();
byte[] bytes = objectMapper.writeValueAsBytes(updatedTodo);
when(repository.save(Mockito.any(Todo.class))).thenReturn(updatedTodo);
mvc.perform(put("/todos/{id}", 1L)
.contentType(MediaType.APPLICATION_JSON)
.content(bytes))
.andExpect(status().isNoContent());
verify(repository, times(0)).delete(1L);
verify(repository, times(1)).save(Mockito.any(Todo.class));
verifyNoMoreInteractions(repository);
}
@Test
public void testUpdateDifferentIds() throws Exception {
final Todo updatedTodo = new Todo(99L, "z", true);
ObjectMapper objectMapper = new ObjectMapper();
byte[] bytes = objectMapper.writeValueAsBytes(updatedTodo);
when(repository.save(Mockito.any(Todo.class))).thenReturn(updatedTodo);
mvc.perform(put("/todos/{id}", 1L)
.contentType(MediaType.APPLICATION_JSON)
.content(bytes))
.andExpect(status().isNoContent());
verify(repository, times(1)).delete(1L);
verify(repository, times(1)).save(Mockito.any(Todo.class));
verifyNoMoreInteractions(repository);
}
@Test
public void testDelete() throws Exception {
// this is how to test a void method with Mockito
// doThrow(new IllegalArgumentException()).when(repository).delete(null);
mvc.perform(delete("/todos/{id}", 1L))
.andExpect(status().isNoContent());
}
}
關于系統用例的書籍,太多。不想在這里去解釋什么是系統用例。但為什么要寫系統用例呢,又如何寫好呢?
寫系統用例是為了更清晰的展示系統的業務場景的功能實現。也是為了給程序員參考的一個圖。同時也是與客戶溝通的橋梁。很多東西,千言萬語,不如一張圖那么直觀。但在很多項目中,用例分析這個過程被忽略而過。
程序員往往只看到文本的需求,就自己開始做了,對于小項目或許這樣可以,如果是大項目,后期肯定崩潰。
一個良好的系統用例,用圖形的方式描述了客戶的要求:
1. 有那些人去參與這個事件。
2.這些人具體要做什么 (可以理解為調用的方法)
3.這些人做這個事情,需要什么先決條件 (可以理解為參數,包括權限等等)
4.這些在做這些事情的時候,需要第三方幫忙嗎?或者需要第三方系統接口嗎?
5.做完這些事情,應該達到一個什么樣的目的,也就是結果,這個結果會是下一個用例的輸入嗎?
當你有著人物,事件,參數,輸入,輸出的一張圖 擺在眼前的時候,所有的事情的都清晰了。
看著這張圖,就可以寫出 相關的接口程序,實現方法等。
通過大量的系統用例,可以提取出公共的用例,比如權限等。從而抽象出公共的實現方法,才不會導致同一個方法,不同的程序員各自實現了一套。
以圖書為例子,列表說明一個用例的主要部分,以及要表達清楚的地方。
用例名稱 | bu_借閱圖書 |
用例描述 | 借閱人通過此用例向系統查詢并提交借書請求 |
執行者 | 借閱人 |
前置條件 | 1. 借閱人借閱證件在有效期內 2. 借閱人沒有逾期未歸還的圖書 |
后置條件 | 1. 創建借書定單 2. 更新借閱人借閱記錄 |
主過程描述 | 1用戶用借閱證提供的帳號登錄系統,計算機顯示我的圖書館界面 2.用戶選擇查詢圖書,計算機顯示查詢界面 3.用戶按書名、作者、出版社查詢,計算機顯示查詢結果 4.用戶可單選或多選書本,并確認借閱。計算機顯示確認借閱圖書清單。 5.用戶選擇確認借閱,計算機顯示借閱定單及費用 6用戶選擇提交定單,計算機顯示提交結果和定單號 7.計算機執行后置條件。用例結束 |
分支過程描述 | 2.1.1用戶選擇查看原有定單,計算機執行4; 4.1.1用戶可單選或多選書本,放入借書籃,計算機顯示借書籃現有內容 4.1.2.1.1用戶選擇繼續借書,計算機執行2; 4.1.2.2.1用戶選擇提交借書籃,計算機執行4 4.2.1 用戶選擇放棄,計算機執行2; 6.1.1用戶選擇保存定單,計算機保存并執行1; 6.2.1用戶選擇放棄,計算機執行1; |
異常過程描述 | 1.1.1借閱證已過期,拒絕登錄,用例結束 1.2.1借閱人有逾期未歸還書本,啟動bu_歸還圖書用例 5.1.1用戶余額不足,計算機顯示余額和所需金額 5.1.2.1.1用戶選擇續費,啟動bu_交納借閱費用例 5.1.2.2.1用戶選擇放棄,計算機執行1 |
業務規則 | 4.至少選擇一本,至多選擇三本 |
涉及的業務實體 | Be_費用記錄 Be_圖書 Be_借書籃 Be_借閱定單 Be_借閱證 |
啟動STORAGE SERVER
fdfs_storaged /etc/fdfs/storage.conf
啟動TRACKER SERVER
fdfs_trackerd /etc/fdfs/tracker.conf
啟動NGINX
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
觀看LOG
tail -f /home/storage1/fastdfs/logs/storaged.log
檢查STORAGE SERVER
fdfs_monitor /etc/fdfs/client.conf
刪除STORAGE SERVER
fdfs_monitor /etc/fdfs/client.conf delete group1 10.120.151.114
重啟
/usr/local/bin/restart.sh fdfs_storaged /etc/fdfs/storage.conf
/usr/local/bin/restart.sh fdfs_trackerd /etc/fdfs/storage.conf
停止
/usr/local/bin/stop.sh fdfs_storaged /etc/fdfs/storage.conf
/usr/local/bin/stop.sh fdfs_trackerd /etc/fdfs/storage.conf
測試上傳
fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h
查詢文件是否存在
fdfs_file_info /etc/fdfs/client.conf group1/M00/00/D1/CniXclQ0vdfCNdkzAABGC4v7nb4822.png
STORAGE SERVER的狀態通常有七種:
# FDFS_STORAGE_STATUS:INIT :初始化,尚未得到同步已有數據的源服務器
# FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有數據的源服務器
# FDFS_STORAGE_STATUS:SYNCING :同步中
# FDFS_STORAGE_STATUS:DELETED :已刪除,該服務器從本組中摘除
# FDFS_STORAGE_STATUS:OFFLINE :離線
# FDFS_STORAGE_STATUS:ONLINE :在線,尚不能提供服務
# FDFS_STORAGE_STATUS:ACTIVE :在線,可以提供服務
正常狀態必須是ACTIVE,如果運行以下命令:
fdfs_monitor /etc/fdfs/client.conf
發現有以下狀態的服務器:
Storage 4:
ip_addr = 10.120.151.114 WAIT_SYNC
經過各種重啟都不解決問題,只好先刪除,再加入
#從集群中刪除
fdfs_monitor /etc/fdfs/client.conf delete group1 10.120.151.114
#在114服務器中,刪除數據文件夾
rm -rf /home/storage1/fastdfs/data
#重啟114節點
fdfs_storaged /etc/fdfs/storage.conf
重新查狀態
fdfs_monitor /etc/fdfs/client.conf
狀態變正常了。