jython-2 |
jython-2 |
|
导包:jython-2.7-b1.jar
-----------------------------------------
-----------------------------------------
java类文件:
package com.newbee;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.python.core.PyDictionary;
import org.python.core.PyException;
import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyList;
import org.python.core.PyObject;
import org.python.core.PyString;
public class SimpleEmbedded {
public static void main(String[] args) throws PyException, IOException {
// Java
EmployeeType eType =
(EmployeeType) JythonFactory.getInstance().getJavaObjectFromJythonFile("com.newbee.EmployeeType", "Employee.py");
System.out.println("Employee Name: " + eType.getEmployeeFirst() + " " + eType.getEmployeeLast());
System.out.println("Employee ID: " + eType.getEmployeeId());
// Jython
PyObject pyObject = JythonFactory.getInstance().getPyObjectFromJythonFile("Employee", "Employee.py");
System.out.println("+++="+pyObject.invoke("getEmployeeId"));
pyObject.invoke("setEmployeeId",new PyString("1999"));
System.out.println("+++="+pyObject.invoke("getEmployeeId"));
// Jython Function
PyFunction pyFunction = JythonFactory.getInstance().getPyFunctionFromJythonFile("getNunmberValue", "Employee.py");
System.out.println("***="+pyFunction.__call__(new PyInteger(10)));
PyFunction py = JythonFactory.getInstance().getPyFunctionFromJythonFile("adder", "my_utils.py");
System.out.println("***="+py);
System.out.println("***="+py.__call__(new PyInteger(10),new PyInteger(10)));
System.out.println("**************************************************************");
// PyFunction py_2 = JythonFactory.getInstance().getPyFunctionFromJythonFile("getPersonNew", "my_class.py");
// System.out.println("***="+py_2.__call__(new PyString("孙悟空")));
/***对应demo01.py***/
PyFunction py_2 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handCollection", "demo01.py");
List list = new ArrayList();
list.add(1);
list.add(2);
List newList = (List)py_2.__call__(new PyList(list));
for(int i = 0; i < newList.size(); i++){
Object obj = newList.get(i);
if(obj instanceof String){
System.out.println("字符串的值 = "+newList.get(i).toString());
}else if(obj instanceof Integer){
int temp = (Integer)obj;
System.out.println("字符串的值 = "+temp);
}
}
// System.out.println("***="+py_2.__call__(new PyList(list)));
System.out.println("----------------西游记----------------");
/***对应demo02.py***/
PyFunction py_3 = JythonFactory.getInstance().getPyFunctionFromJythonFile("getUserList", "demo02.py");
List<UserVo> list_3 = new ArrayList<UserVo>();
UserVo u = new UserVo();
u.setId(1);
u.setUsername("唐僧");
u.setUserpass("tangseng");
UserVo u2 = new UserVo();
u2.setId(2);
u2.setUsername("八戒");
u2.setUserpass("bajie");
list_3.add(u);
list_3.add(u2);
List<UserVo> newList_3 = (List<UserVo>)py_3.__call__(new PyList(list_3));
for(int i = 0; i < newList_3.size(); i++){
Object obj = newList_3.get(i);
if(obj instanceof String){
System.out.println("字符串的值 = "+newList_3.get(i).toString());
}else if(obj instanceof Integer){
int temp = (Integer)obj;
System.out.println("字符串的值 = "+temp);
}else if(obj instanceof UserVo){
UserVo uv = (UserVo)obj;
System.out.println("名称 = "+uv.getUsername()+", 密码 = "+uv.getUserpass());
}
}
// System.out.println("***="+py_2.__call__(new PyList(list)));
System.out.println("+++++++++++++++++读取文件+++++++++++++++++++++++");
PyFunction py_4 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryFileContent.py");
Map map = new HashMap();
map = (Map)py_4.__call__(new PyString("D:\\Java 开发工具包\\jython\\demo\\project_13F\\a.txt"));
System.out.println("传说你这边有问题没解决");
for(Object key : map.keySet()){
System.out.println("(key,value) = ("+key+","+map.get(key)+")");
}
System.out.println("传说你这边有问题没解决");
System.out.println("size = "+map.size());
System.out.println("+++++++++++++++++map方式+++++++++++++++++++++++");
PyFunction py_5 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryFileContent2.py");
Map map2 = new HashMap();
map2.put("DHY:TD-M01-010-001", 11);
map2.put("DHY:TD-M01-010-002", 22);
map2.put("DHY:TD-M01-010-003", 33);
map2.put("DHY:TD-M01-010-004", 44);
map2.put("DHY:TD-M01-010-005", 55);
map2.put("DHY:TD-M01-010-006", 66);
FileInputStream fis = new FileInputStream(new File("D:\\Java 开发工具包\\jython\\demo\\project_13F\\a.txt"));
File tempFile = new File("D:\\Java 开发工具包\\jython\\demo\\project_13F");
if(!tempFile.exists()){
tempFile.mkdir();
}
FileOutputStream fos = new FileOutputStream(new File(tempFile,"b.txt"));
for(Object key : map2.keySet()){
byte[] b = new byte[2048];
int len = 0;
String content = key +"="+map2.get(key)+"\r\n";
b = content.getBytes();
fos.write(b, 0, content.length());
}
fos.flush();
fos.close();
System.out.println("###################999999999999######################");
py_5.__call__(new PyString("D:\\Java 开发工具包\\jython\\demo\\project_13F\\b.txt"));
System.out.println("###################66666######################");
Map<PyObject , PyObject> map3 = new HashMap<PyObject , PyObject>();
map3.put(new PyString("DHY:TD-M01-010-001"), new PyInteger(11));
map3.put(new PyString("DHY:TD-M01-010-002"), new PyInteger(22));
map3.put(new PyString("DHY:TD-M01-010-003"), new PyInteger(33));
map3.put(new PyString("DHY:TD-M01-010-004"), new PyInteger(44));
PyFunction py_6 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryFileContent3.py");
PyDictionary pb = new PyDictionary(map3);
PyDictionary pp = (PyDictionary)py_6.__call__(pb);
Set<String> mapSet = pp.keySet();
for(String key : mapSet)
{
System.out.println("打印map集合key = "+key+", value = "+pp.get(key));
}
// System.out.println("打印map集合"+pp);
System.out.println("###################77777######################");
Map<PyObject , PyObject> map_7 = new HashMap<PyObject , PyObject>();
map_7.put(new PyString("DHY:TD-M01-010-001"), new PyInteger(11));
map_7.put(new PyString("DHY:TD-M01-010-002"), new PyInteger(22));
map_7.put(new PyString("DHY:TD-M01-010-003"), new PyInteger(33));
map_7.put(new PyString("DHY:TD-M01-010-004"), new PyInteger(44));
PyFunction py_7 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryContent4.py");
PyDictionary pb_7 = new PyDictionary(map_7);
PyDictionary pp_7 = (PyDictionary)py_7.__call__(pb_7);
Set<String> mapSet_7 = pp_7.keySet();
for(String key : mapSet_7)
{
System.out.println("打印map集合key = "+key+", value = "+pp_7.get(key));
}
System.out.println("###################8888######################");
// List<BomVo> m_list = new ArrayList<BomVo>();
// m_list.add(new BomVo("DHY:TD-P01-010-001"));
// m_list.add(new BomVo("DHY:TD-P01-010-002"));
// m_list.add(new BomVo("DHY:TD-P01-010-003"));
// m_list.add(new BomVo("DHY:TD-P01-010-004"));
// PyList bBomList = new PyList(m_list);
PyList bBomList = new PyList();
bBomList.add(new BomVo("DHY:TD-P01-010-001"));
bBomList.add(new BomVo("DHY:TD-P01-010-002"));
bBomList.add(new BomVo("DHY:TD-P01-010-003"));
bBomList.add(new BomVo("DHY:TD-P01-010-004"));
PyFunction py_8 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "objContent.py");
PyList re_list = (PyList)py_8.__call__(new PyInteger(12),bBomList);
for(int i = 0; i < re_list.size(); i++){
BomVo b = (BomVo)re_list.get(i);
System.out.println("dhy = "+b.getBom_no()+", headerText = "+b.getHeaderText());
}
}
}
-------------------------------------
2. queryContent4.py
def handler(mp):
nmp = {}
for(k,v) in mp.items():
# print k,v
if k == 'DHY:TD-M01-010-001':
# print 'key is',k
nmp['DHY:TD-P01-010-001'] = v
nmp['DHY:TD-P01-010-002'] = v
nmp['DHY:TD-P01-010-003'] = v
elif k == 'DHY:TD-M01-010-002':
num = v
if v>0:
p001 = 'DHY:TD-P01-010-001'
if p001 in nmp:
p001_val = nmp[p001]
nmp[p001] = num + p001_val
else:
nnmp[p001] = num
elif k == 'DHY:TD-M01-010-003':
num = v
p003 = 'DHY:TD-P01-010-003'
p003_val = 0
if p003 in nmp:
p003_val = nmp[p003]
if p003_val > 0:
nmp[p003] = num + p003_val
else:
nmp[p003] = num
elif k == 'DHY:TD-M01-010-004':
nmp['DHY:TD-P01-010-004'] = 100
else:
pass
del mp['DHY:TD-M01-010-001']
del mp['DHY:TD-M01-010-002']
del mp['DHY:TD-M01-010-003']
del mp['DHY:TD-M01-010-004']
return nmp
----------------------------------------------
3. objContent.py
from com.newbee import BomVo
class Bom(BomVo):
def __init__(self):
self.bom_no = 'bom_no'
self.id = 'id'
self.bom_num = 'bom_num'
self.headerText = 'headerText'
self.bom_sort_no = 'bom_sort_no'
self.re_address = 're_address'
def setBom_no(self,bom_no):
self.bom_no = bom_no
def setId(self,id):
self.id = id
def setBom_num(self,bom_num):
self.bom_num = bom_num
def setHeaderText(self,headerText):
self.headerText = headerText
def setBom_sort_no(self,bom_sort_no):
self.bom_sort_no = bom_sort_no
def setRe_address(self,re_address):
self.re_address = re_address
def getBom_no(self):
return self.bom_no
def getId(self):
return self.id
def getBom_num(self):
return self.bom_num
def getHeaderText(self):
return self.HeaderText
def getBom_sort_no(self):
return self.bom_sort_no
def getRe_address(self):
return self.re_address
def handler(sell_id,bBomList):
newBBomList = []
newBBomMap = {}
ind = 0
for sBom in range(len(bBomList)):
b = bBomList[sBom]
# print b
bDhy = b.getBom_no()
print bDhy
if bDhy == 'DHY:TD-P01-010-001':
b.setHeaderText('hexinwang/huaweichanpingxian')
## bBom = BomVo(bDhy,'hexinwang/huaweichanpingxian')
elif bDhy == 'DHY:TD-P01-010-002':
b.setHeaderText('hexinwang/huaweinengji')
## bBom = BomVo(bDhy,'hexinwang/huaweinengji')
elif bDhy == 'DHY:TD-P01-010-003':
b.setHeaderText('hexinwang/huaweinengji')
## bBom = BomVo(bDhy,'hexinwang/huaweinengji')
elif bDhy == 'DHY:TD-P01-010-004':
b.setHeaderText('hexinwang/waicai')
## bBom = BomVo(bDhy,'hexinwang/waicai')
print b.getHeaderText()
newBBomList.append(b)
ind = ind + 1
# newBBomMap[sell_id] = newBBomList
# return newBBomMap
return newBBomList
|
jython |
jython |
|
导包:jython-2.7-b1.jar
-----------------------------------------
-----------------------------------------
java类文件:
package com.newbee;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.python.core.PyDictionary;
import org.python.core.PyException;
import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyList;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.core.PyStringMap;
public class SimpleEmbedded {
public static void main(String[] args) throws PyException, IOException {
// Java
EmployeeType eType =
(EmployeeType) JythonFactory.getInstance().getJavaObjectFromJythonFile("com.newbee.EmployeeType", "Employee.py");
System.out.println("Employee Name: " + eType.getEmployeeFirst() + " " + eType.getEmployeeLast());
System.out.println("Employee ID: " + eType.getEmployeeId());
// Jython
PyObject pyObject = JythonFactory.getInstance().getPyObjectFromJythonFile("Employee", "Employee.py");
System.out.println("+++="+pyObject.invoke("getEmployeeId"));
pyObject.invoke("setEmployeeId",new PyString("1999"));
System.out.println("+++="+pyObject.invoke("getEmployeeId"));
// Jython Function
PyFunction pyFunction = JythonFactory.getInstance().getPyFunctionFromJythonFile("getNunmberValue", "Employee.py");
System.out.println("***="+pyFunction.__call__(new PyInteger(10)));
PyFunction py = JythonFactory.getInstance().getPyFunctionFromJythonFile("adder", "my_utils.py");
System.out.println("***="+py);
System.out.println("***="+py.__call__(new PyInteger(10),new PyInteger(10)));
System.out.println("**************************************************************");
// PyFunction py_2 = JythonFactory.getInstance().getPyFunctionFromJythonFile("getPersonNew", "my_class.py");
// System.out.println("***="+py_2.__call__(new PyString("孙悟空")));
/***对应demo01.py***/
PyFunction py_2 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handCollection", "demo01.py");
List list = new ArrayList();
list.add(1);
list.add(2);
List newList = (List)py_2.__call__(new PyList(list));
for(int i = 0; i < newList.size(); i++){
Object obj = newList.get(i);
if(obj instanceof String){
System.out.println("字符串的值 = "+newList.get(i).toString());
}else if(obj instanceof Integer){
int temp = (Integer)obj;
System.out.println("字符串的值 = "+temp);
}
}
// System.out.println("***="+py_2.__call__(new PyList(list)));
System.out.println("----------------西游记----------------");
/***对应demo02.py***/
PyFunction py_3 = JythonFactory.getInstance().getPyFunctionFromJythonFile("getUserList", "demo02.py");
List<UserVo> list_3 = new ArrayList<UserVo>();
UserVo u = new UserVo();
u.setId(1);
u.setUsername("唐僧");
u.setUserpass("tangseng");
UserVo u2 = new UserVo();
u2.setId(2);
u2.setUsername("八戒");
u2.setUserpass("bajie");
list_3.add(u);
list_3.add(u2);
List<UserVo> newList_3 = (List<UserVo>)py_3.__call__(new PyList(list_3));
for(int i = 0; i < newList_3.size(); i++){
Object obj = newList_3.get(i);
if(obj instanceof String){
System.out.println("字符串的值 = "+newList_3.get(i).toString());
}else if(obj instanceof Integer){
int temp = (Integer)obj;
System.out.println("字符串的值 = "+temp);
}else if(obj instanceof UserVo){
UserVo uv = (UserVo)obj;
System.out.println("名称 = "+uv.getUsername()+", 密码 = "+uv.getUserpass());
}
}
// System.out.println("***="+py_2.__call__(new PyList(list)));
System.out.println("+++++++++++++++++读取文件+++++++++++++++++++++++");
PyFunction py_4 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryFileContent.py");
Map map = new HashMap();
map = (Map)py_4.__call__(new PyString("D:\\Java 开发工具包\\jython\\demo\\project_13F\\a.txt"));
System.out.println("传说你这边有问题没解决");
for(Object key : map.keySet()){
System.out.println("(key,value) = ("+key+","+map.get(key)+")");
}
System.out.println("传说你这边有问题没解决");
System.out.println("size = "+map.size());
System.out.println("+++++++++++++++++map方式+++++++++++++++++++++++");
PyFunction py_5 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryFileContent2.py");
Map map2 = new HashMap();
map2.put("DHY:TD-M01-010-001", 11);
map2.put("DHY:TD-M01-010-002", 22);
map2.put("DHY:TD-M01-010-003", 33);
map2.put("DHY:TD-M01-010-004", 44);
map2.put("DHY:TD-M01-010-005", 55);
map2.put("DHY:TD-M01-010-006", 66);
FileInputStream fis = new FileInputStream(new File("D:\\Java 开发工具包\\jython\\demo\\project_13F\\a.txt"));
File tempFile = new File("D:\\Java 开发工具包\\jython\\demo\\project_13F");
if(!tempFile.exists()){
tempFile.mkdir();
}
FileOutputStream fos = new FileOutputStream(new File(tempFile,"b.txt"));
for(Object key : map2.keySet()){
byte[] b = new byte[2048];
int len = 0;
String content = key +"="+map2.get(key)+"\r\n";
b = content.getBytes();
fos.write(b, 0, content.length());
}
fos.flush();
fos.close();
System.out.println("###################999999999999######################");
py_5.__call__(new PyString("D:\\Java 开发工具包\\jython\\demo\\project_13F\\b.txt"));
System.out.println("###################66666######################");
Map<PyObject , PyObject> map3 = new HashMap<PyObject , PyObject>();
map3.put(new PyString("DHY:TD-M01-010-001"), new PyInteger(11));
map3.put(new PyString("DHY:TD-M01-010-002"), new PyInteger(22));
map3.put(new PyString("DHY:TD-M01-010-003"), new PyInteger(33));
map3.put(new PyString("DHY:TD-M01-010-004"), new PyInteger(44));
PyFunction py_6 = JythonFactory.getInstance().getPyFunctionFromJythonFile("handler", "queryFileContent3.py");
PyDictionary pb = new PyDictionary(map3);
PyDictionary pp = (PyDictionary)py_6.__call__(pb);
Set<String> mapSet = pp.keySet();
for(String key : mapSet)
{
System.out.println("打印map集合key = "+key+", value = "+pp.get(key));
}
// System.out.println("打印map集合"+pp);
}
}
--------------------------------------------
--------------------------------------------
jython脚本:
1. queryFileContent.py
def handler(filePath):
result = ""
f = open(filePath,'r')
##lineContent = f.readline()
##while(f.readline()):
## result.append(lineContent)
result = f.read()
content = result.split(",\n")
key_value = {}
for i in range(len(content)):
## print(content[i])
splitRes = content[i].split('=')
key = splitRes[0]
value = splitRes[1]
key_value[key] = value
print key_value
return key_value
##for i in range(len(content)):
2. queryFileContent2.py
def handler(filePath):
result = ""
f = open(filePath,'r')
##lineContent = f.readline()
##while(f.readline()):
## result.append(lineContent)
result = f.read()
content = result.split(",\n")
key_value = {}
for i in range(len(content)):
## print(content[i])
splitRes = content[i].split('=')
key = splitRes[0]
if(key == "DHY:TD-M01-010-001"):
key = "DHY:TD-P01-010-001"
elif(key == "DHY:TD-M01-010-002"):
key = "DHY:TD-P01-010-002"
elif(key == "DHY:TD-M01-010-003"):
key = "DHY:TD-P01-010-003"
elif(key == "DHY:TD-M01-010-004"):
key = "DHY:TD-P01-010-004"
elif(key == "DHY:TD-M01-010-005"):
key = "DHY:TD-P01-010-005"
elif(key == "DHY:TD-M01-010-006"):
key = "DHY:TD-P01-010-006"
value = splitRes[1]
key_value[key] = value
print key +" = "+ value
## print key_value
return key_value
3. queryFileContent3.py
def handler(mp):
key_obj = mp.keys()
key_val = mp.values()
# print key_obj , key_val
for (k, v) in mp.items():
print k, v
return mp
|
holdpuke_8 |
holdpuke_8 |
|
jar包:commons-io-2.4.jar
|
holdpuke_7 |
holdpuke_7 |
|
包:com.youth.game.util
1. CardUtils.java
package com.youth.game.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.youth.game.base.Card;
import com.youth.game.base.CardSuit;
import com.youth.game.base.CardType;
import com.youth.game.base.CountCard;
import com.youth.game.exception.CardFormatException;
import com.youth.game.exception.CardNumberException;
/**
* 处理纸牌的工具类
* @author hadoop
*
*/
public class CardUtils {
private static final CardUtils cardUtils;
static{
cardUtils = new CardUtils();
}
private CardUtils() {
}
public static CardUtils newInstance(){
return cardUtils;
};
/**
* 将一个list中的五张牌 转换成一个字符串 用空格分开
* @return
* @throws CardNumberException
*/
public static String cardsToString(List<Card> cards) throws CardNumberException{
validateList(cards, 5);
return null;
}
public CardType getCardType(List<Card> cards) throws CardNumberException{
validateList(cards, 5);
return null;
}
/**
* 统计牌出现的次数
* @param cards
* @return
* @throws CardNumberException
*/
public static List<CountCard> countCard(List<Card> cards) {
Map<Integer, List<Card>> map = new HashMap<Integer, List<Card>>();
for (Card card : cards) {
int val = card.getValueIndex();
if (map.get(val)!=null) {
map.get(val).add(card);
}else {
List<Card> list = new ArrayList<Card>();
list.add(card);
map.put(val, list);
}
}
List<CountCard> countCard = new ArrayList<CountCard>();
for (Integer val : map.keySet()) {
CountCard cardTemp = new CountCard(map.get(val));
countCard.add(cardTemp);
}
return countCard;
}
/**
* 验证输入的牌的数量是否正确
* @param cards 输入的牌的集合
* @param number 正确情况下 牌的数量
* @throws CardNumberException
*/
private static void validateList(List<Card> cards,int number) throws CardNumberException{
if (cards==null||cards.size()!=number) {
throw new CardNumberException("纸牌的数量有错!");
}
};
/**
* 判断是否为同花
* @param list
* @return
*/
public static boolean isFlush(List<Card> list){
CardSuit suit = null;
for (Card card : list) {
if (suit==null) {
suit = card.getCardSuit();
}else if(!suit.equals(card.getCardIndex())) {
return false;
}
}
return true;
}
/**
* 判断是否为顺子
* @param list
* @return
*/
public static boolean isStraight(List<Card> list){
Collections.sort(list);
//将牌的最大值和最小值相减的绝对值 如果结果等于 集合的长度减一 那么就为顺子
int size = list.size();
int minVal = list.get(0).getValueIndex();
int maxVal = list.get(size-1).getValueIndex();
if (Math.abs(maxVal-minVal)==size-1) {
return true;
}else if (minVal==0&& maxVal==12) {
//注意 此处处理 A 2 3 4 5 的情况
maxVal = list.get(size-2).getValueIndex();
if(Math.abs(maxVal-minVal)==size-2){
return true;
}
}
return false;
}
public static List<Card> string2Cards(String cards) throws CardFormatException{
String[] str = cards.trim().split(" ");
List<Card> cardList = new ArrayList<Card>();
for (String string : str) {
cardList.add(new Card(string));
}
return cardList;
}
}
|
holdpuke_6 |
holdpuke_6 |
|
包:com.youth.game.test.io
1. TestReadFile.java
package com.youth.game.test.io;
import java.util.List;
import org.junit.Test;
import com.youth.game.domain.Bout;
import com.youth.game.domain.BoutDetails;
import com.youth.game.io.OperationFile;
public class TestReadFile {
@Test
public void testReadFile(){
List<Bout> bouts = new OperationFile().readFile("showdown.txt");
System.out.println("******************************************");
System.out.println("******************************************");
for (Bout bout : bouts) {
System.out.println(bout.getId());
List<BoutDetails> details = bout.getDetails();
for (BoutDetails detail : details) {
System.out.print(detail.getUser().getId()+" ");
System.out.println(detail.getCards());
}
System.out.println(bout.getPublicCards());
System.out.println();
System.out.println("##################################");
}
}
}
|
holdpuke_5 |
holdpuke_5 |
|
包:com.youth.game.io
1. OperationFile.java
package com.youth.game.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.youth.game.base.Card;
import com.youth.game.base.Constant;
import com.youth.game.base.FiveCards;
import com.youth.game.domain.Bout;
import com.youth.game.domain.BoutDetails;
import com.youth.game.domain.User;
import com.youth.game.exception.CardFormatException;
import com.youth.game.util.CardUtils;
public class OperationFile {
public List<Bout> readFile(String path){
File file = new File(Constant.rootPath+path);
System.out.println(file.getPath());
BufferedReader reader = null;
List<Bout> bouts =new ArrayList<Bout>();
try {
reader = new BufferedReader(new FileReader(file));
String line = null;
Bout bout = null;
List<BoutDetails> details =new ArrayList<BoutDetails>();
while((line = reader.readLine()) !=null){
// System.out.println(line);
if(line.equalsIgnoreCase("")){
// System.out.println("##############");
}else {
line = line.trim();
if (line.indexOf(" ")==-1) {
//不包含空字符串 ,那么就是局数信息
bout = new Bout();
bout.setId(Long.valueOf(line));
bouts.add(bout); //读取一个新局时 就添加到总的局数中
details =new ArrayList<BoutDetails>();
bout.setDetails(details);
}else{
//如果包含空格 那么就可能是 用户的信息,或者是 公共的牌
String[] cards = line.split(" ");
if (cards.length==3) {
//此行是用户的信息
User user = new User();
user.setId(Long.valueOf(cards[0].trim()));
BoutDetails detail = new BoutDetails();
detail.setUser(user);
detail.setCards(line.substring(line.indexOf(" ")));
details.add(detail);
}else if(cards.length==5){
//此行是公共牌的信息
bout.setPublicCards(line);
}else{
System.out.println("数据错误了 "+cards.length);
}
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(reader!=null)
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return bouts;
}
public void writeResult(String fileName,List<Bout> bouts) throws CardFormatException{
for (Bout bout : bouts) {
String publicCards =bout.getPublicCards();
List<Card> cardsList = CardUtils.string2Cards(publicCards);
// FiveCards fiveCards = new FiveCards(cards)
}
}
}
|
holdpuke_4 |
holdpuke_4 |
|
包:com.youth.game.exception
1. CardFormatException.java
package com.youth.game.exception;
/**
* 牌的格式异常 例如:H23, Hp 等
* @author hadoop
*
*/
public class CardFormatException extends Exception{
/**
*
*/
private static final long serialVersionUID = 4083975168364689380L;
public CardFormatException() {
super();
}
public CardFormatException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
super(message, cause);
}
public CardFormatException(String message, Throwable cause) {
super(message, cause);
}
public CardFormatException(String message) {
super(message);
}
public CardFormatException(Throwable cause) {
super(cause);
}
}
2. CardNumberException.java
package com.youth.game.exception;
/**
* 纸牌的个数异常,例如:需要5张牌,可是只传给了4张 或者6张
* @author hadoop
*
*/
public class CardNumberException extends Exception
{
private static final long serialVersionUID = 6461628982265051719L;
public CardNumberException() {
super();
}
public CardNumberException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
super(message, cause);
}
public CardNumberException(String message, Throwable cause) {
super(message, cause);
}
public CardNumberException(String message) {
super(message);
}
public CardNumberException(Throwable cause) {
super(cause);
}
}
|
holdpuke_3 |
holdpuke_3 |
|
包:com.youth.game.domain
1. Bout.java
package com.youth.game.domain;
import java.util.List;
/**
* 回合
* @author hadoop
*
*/
public class Bout {
private long id;
/**
* 公共牌,一共有五张,用" "分割 CT D3 SJ D9 DA
*/
private String publicCards ;
private List<User> users; //参赛用户;
private List<BoutDetails> details;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getPublicCards() {
return publicCards;
}
public void setPublicCards(String publicCards) {
this.publicCards = publicCards;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public List<BoutDetails> getDetails() {
return details;
}
public void setDetails(List<BoutDetails> details) {
this.details = details;
}
}
2. BoutDetails.java
package com.youth.game.domain;
public class BoutDetails {
private long id;
private Bout bout; //所属回合
private User user;//参赛的用户
private int seatNumber; //用户的座位号
private String cards; //用户所拥有的牌
private String showCards;//用户最终选择的牌 (自己的牌 和公共牌的结合后,比输赢的牌);
private String cardType; //比输赢时的牌型 显示的为 FULL_HOUSE 等信息
private boolean result; //输赢结果;
private long score ; //得分;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Bout getBout() {
return bout;
}
public void setBout(Bout bout) {
this.bout = bout;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public int getSeatNumber() {
return seatNumber;
}
public void setSeatNumber(int seatNumber) {
this.seatNumber = seatNumber;
}
public String getCards() {
return cards;
}
public void setCards(String cards) {
this.cards = cards;
}
public String getShowCards() {
return showCards;
}
public void setShowCards(String showCards) {
this.showCards = showCards;
}
public String getCardType() {
return cardType;
}
public void setCardType(String cardType) {
this.cardType = cardType;
}
public boolean isResult() {
return result;
}
public void setResult(boolean result) {
this.result = result;
}
public long getScore() {
return score;
}
public void setScore(long score) {
this.score = score;
}
}
3. User.java
package com.youth.game.domain;
import java.util.Date;
public class User {
private long id;
private String name;
private String password;
private long score; //游戏积分
private long winCount;//获胜的次数
private long drawCount;//和局的次数
private long fleeCount;//逃跑的次数
private boolean disable;//账户是否可用;
private Date registrationDate;//注册时间;
private Date lastLoginDate;//最后登录时间
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public long getScore() {
return score;
}
public void setScore(long score) {
this.score = score;
}
public long getWinCount() {
return winCount;
}
public void setWinCount(long winCount) {
this.winCount = winCount;
}
public long getDrawCount() {
return drawCount;
}
public void setDrawCount(long drawCount) {
this.drawCount = drawCount;
}
public long getFleeCount() {
return fleeCount;
}
public void setFleeCount(long fleeCount) {
this.fleeCount = fleeCount;
}
public boolean isDisable() {
return disable;
}
public void setDisable(boolean disable) {
this.disable = disable;
}
public Date getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
public Date getLastLoginDate() {
return lastLoginDate;
}
public void setLastLoginDate(Date lastLoginDate) {
this.lastLoginDate = lastLoginDate;
}
}
|
holdpuke_2 |
holdpuke_2 |
|
包:com.youth.game.dao
1. BaseDao.java
package com.youth.game.dao;
public interface BaseDao<T> {
public void save(T t);
public void update(T t);
public void delete(T t);
}
2. BoutDao.java
package com.youth.game.dao;
import com.youth.game.domain.Bout;
public interface BoutDao extends BaseDao<Bout>{
}
3. BoutDetailsDao.java
package com.youth.game.dao;
import com.youth.game.domain.BoutDetails;
public interface BoutDetailsDao extends BaseDao<BoutDetails> {
}
4. UserDao.java
package com.youth.game.dao;
import com.youth.game.domain.User;
public interface UserDao extends BaseDao<User> {
}
|
holdpuke_1 |
holdpuke_1 |
|
包:com.youth.game.base
1. Card.java
package com.youth.game.base;
import java.util.Arrays;
import com.youth.game.exception.CardFormatException;
public class Card implements Comparable<Card>{
//牌的索引集,一共有52张牌
private static final byte[] cards ={
0,1,2,3,4,5,6,7,8,9,10,11,12,//花色为:黑桃
13,14,15,16,17,18,19,20,21,22,23,24,25,//红桃
26,27,28,29,30,31,32,33,34,35,36,37,38,//梅花
39,40,41,42,43,44,45,46,47,48,49,50,51//方块
};
private static final char[] values = {'2','3','4','5','6','7','8','9','T','J','K','Q','A'};
private int cardIndex; //牌的索引
private int valueIndex;//牌的值
private CardSuit cardSuit;//牌的花色
//private int count=0;//用于统计 本张牌出现的次数 辅助字段 主要用于排序
public Card(int cardIndex, int valueIndex) throws CardFormatException {
super();
if (valueIndex <0||valueIndex >51 ||cardIndex<0||cardIndex>12) {
throw new CardFormatException("纸牌的数值有错");
}
this.cardIndex = cardIndex;
this.valueIndex = valueIndex;
byte val= cards[cardIndex];
try {
this.cardSuit = CardSuit.int2CardSuit(val);
} catch (Exception e) {
e.printStackTrace();
throw new CardFormatException("纸牌的颜色信息有错");
}
}
public Card(String value) throws CardFormatException {
super();
String suit =value.substring(0, 1);
String val =value.substring(1, value.length());
this.valueIndex = Arrays.binarySearch(values, val.charAt(0));
if (this.valueIndex <0) {
throw new CardFormatException();
}
try {
this.cardSuit = CardSuit.valueOf(suit);
} catch (Exception e) {
e.printStackTrace();
throw new CardFormatException();
}
this.cardIndex = cardSuit.ordinal()*13+valueIndex;
}
public int getCardIndex() {
return cardIndex;
}
public void setCardIndex(int cardIndex) {
this.cardIndex = cardIndex;
}
public int getValueIndex() {
return valueIndex;
}
public void setValueIndex(int valueIndex) {
this.valueIndex = valueIndex;
}
public CardSuit getCardSuit() {
return cardSuit;
}
public void setCardSuit(CardSuit cardSuit) {
this.cardSuit = cardSuit;
}
//public int getCount() {
// return count;
//}
//public void setCount(int count) {
// this.count = count;
//}
@Override
public String toString() {
return cardSuit.name()+(values[valueIndex]);
}
@Override
public int compareTo(Card o) {
// //先比较纸牌出现的次数 次数多的放在前面
// if(this.count!=o.getCount()){
// return this.count -o.getCount();
// }
int val = valueIndex%13-o.getValueIndex()%13;
//如果牌的数值相同,那么就比较牌的花色 花色的大小为 黑 >红 >梅 >方
if (val==0) {
return -(this.cardSuit.compareTo( o.cardSuit));
// return -(this.valueIndex/13-o.getValueIndex()/13);
}
return val;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + cardIndex;
result = prime * result + valueIndex;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Card other = (Card) obj;
if (cardIndex != other.cardIndex)
return false;
if (valueIndex != other.valueIndex)
return false;
return true;
}
}
2. CardSuit.java
package com.youth.game.base;
public enum CardSuit {
/**
* 黑桃(spade S)
*/
S,
/**
* 红桃(heart H)
*/
H,
/**
* 梅花(club C)
*/
C,
/**
* 方块(diamond D)
*/
D;
public static CardSuit int2CardSuit(int val){
switch (val/13) {
case 0:
return CardSuit.S;
case 1:
return CardSuit.H;
case 2:
return CardSuit.C;
case 3:
return CardSuit.D;
default:
return null;
}
}
}
3. CardType.java
package com.youth.game.base;
import java.util.List;
import com.youth.game.exception.CardFormatException;
/**
* 牌型
* @author hadoop
*
*/
public enum CardType {
/**
* 皇家同花顺 Royal straight flush (比如黑桃10,J,Q,K,A)
*/
ROYAL_STRAIGHT_FLUSH,
/**
* 同花顺 Straight flush (比如黑桃3,4,5,6,7)
*/
STRAIGHT_FLUSH,
/**
* 四条,炸弹 Four of a kind (比如四条9和一个其它任何牌)
*/
FOUR_OF_A_KIND,
/**
* 满堂彩 Full house (三条加一对)
*/
FULL_HOUSE,
/**
* 清一色 Flush (比如梅花2,5,6,8,J)
*/
FLUSH,
/**
* 一条龙 Straight (比如4,5,6,7,8不同花色混杂)
*/
STRAIGHT,
/**
* 三条 Three of a Kind (比如三个8和其它任意两张单牌)
*/
THREE_OF_A_KIND,
/**
* 两对 Two Pairs
*/
TWO_PAIRS,
/**
* 一对 One Pair
*/
ONE_PAIR,
/**
* 散牌 High Card
*/
HIGH_CARD;
public static CardType getCardType(List<Card> list) throws CardFormatException{
if (list==null||list.size()!=5) {
throw new CardFormatException("纸牌的数量有错!");
}
return null;
};
}
4. Constant.java
package com.youth.game.base;
public class Constant {
//读取文件的路径
public static String rootPath= Constant.class.getClassLoader().getResource("").getPath()+"/../../config/";
private Constant() {
super();
}
}
5. CountCard.java
package com.youth.game.base;
import java.util.List;
/**
* 用于封装统计纸牌数量的一个辅助类
* @author hadoop
*
*/
public class CountCard implements Comparable<CountCard> {
private List<Card> cards; //数值相同的所有的纸牌的集合
private int count; //相同的纸牌的个数 也就是 cards的长度
private int valueIndex; //纸牌的值的索引 也就表示纸牌的值
public CountCard(List<Card> cards) {
super();
if(cards==null || cards.size()==0){
throw new IllegalArgumentException("构造器的参数list长度必须大于1");
}
this.cards = cards;
this.count = cards.size();
this.valueIndex = cards.get(0).getValueIndex();
}
public List<Card> getCards() {
return cards;
}
public int getCount() {
return count;
}
public int getValueIndex() {
return valueIndex;
}
@Override
public int compareTo(CountCard o) {
//先比较 相同牌出现的次数
if (this.count != o.getCount()) {
return this.count - o.getCount();
}
//再比较牌的大小
return this.getCards().get(0).compareTo(o.getCards().get(0));
}
}
6. FiveCards.java
package com.youth.game.base;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.youth.game.util.CardUtils;
/**
* 五张牌组成的对象,也就表示一手牌 只要用于封装数据
* @author hadoop
*
*/
public class FiveCards implements Comparable<FiveCards> {
private List<Card> cards;
private CardType cardType;
private boolean isflush; //是否为同花
private boolean isStraight;//是否为顺子
public FiveCards(List<Card> cards) {
super();
Collections.sort(cards);
this.cards = cards;
//是否为同花
this.isflush = CardUtils.isFlush(cards);
//是否为顺子
this.isStraight = CardUtils.isStraight(cards);
List<CountCard> list = CardUtils.countCard(cards);
//获取牌出现次数的 集合 例如 牌 J J J J K 次数的集合为 4 1
List<Integer> count = new ArrayList<Integer>();
for (CountCard countCard : list) {
count.add(countCard.getCards().size());
}
int size = list.size();
int maxCount = Collections.max(count);//获取出现最多的次数
//可用通过重复的个数来判断 一手牌的类型 后面的注释的数字为 相同牌出现的次数
if (size==2) {
//此时 牌型可能是 4 1 或者 3 2
if(maxCount==4){
this.cardType = CardType.FOUR_OF_A_KIND;
}else {
this.cardType = CardType.FULL_HOUSE;
}
} else if (size==3) {
//此时的牌型可能是 2 2 1 或者 3 1 1
if(maxCount==3){
this.cardType = CardType.THREE_OF_A_KIND;
}else {
this.cardType = CardType.TWO_PAIRS;
}
}else if (size==4) {
//此时的牌型可能是 2 1 1 1
this.cardType = CardType.ONE_PAIR;
}else if (size==5) {
//此时的牌型可能是 1 1 1 1 1
if(isflush&&isStraight){
//同花顺
//获取最大的牌的值 和最小的牌的值
Collections.sort(cards);
int maxVal = cards.get(cards.size()).getValueIndex();
if(maxVal==12){
this.cardType = CardType.ROYAL_STRAIGHT_FLUSH;
}else{
this.cardType = CardType.STRAIGHT_FLUSH;
}
}else if(isStraight) {
this.cardType = CardType.STRAIGHT;
}else if(isflush) {
this.cardType = CardType.FLUSH;
}else {
this.cardType = CardType.HIGH_CARD;
}
}
}
public List<Card> getCards() {
return cards;
}
public CardType getCardType() {
return cardType;
}
@Override
public int compareTo(FiveCards o) {
if (!this.cardType.equals(o.getCardType())) {
return this.cardType.compareTo(o.getCardType());
}
//为顺子或者同花 就需要比较牌的大小
if(isStraight||isflush||cardType.equals(CardType.HIGH_CARD)){
for (int i = cards.size(); i >=0; i--) {
int result = cards.get(i).compareTo(cards.get(i));
if(result!=0){
return result;
}
}
}else {
//有对子的时候
List<CountCard> list = CardUtils.countCard(this.cards);
List<CountCard> otherList = CardUtils.countCard(o.getCards());
Collections.sort(list);
Collections.sort(otherList);
for (int i = list.size(); i >=0; i--) {
int result = list.get(i).compareTo(otherList.get(i));
if(result!=0){
return result;
}
}
}
return 0;
}
}
|
监听器的创建 |
监听器的创建 |
|
public class MemoryListener implements ServletContextListener
|
单元测试-Junit-Dao层 |
单元测试-junit-dao层 |
|
package com.tdtech.cps.test.daotest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.tdtech.cps.dao.BillDao;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext-*.xml" })
public class TestBillDao {
@Autowired
private BillDao billDao;
public BillDao getBillDao() {
return billDao;
}
public void setBillDao(BillDao billDao) {
this.billDao = billDao;
}
@Test
public void testFindBillListGroupBySellClass() {
// Map<SellClass, List<Bill>> map = billDao.findBillListGroupBySellClass(16);
// for (SellClass sell : map.keySet()) {
//// System.out.println(sell.getName()+"===============================");
// for (Bill bill : map.get(sell)) {
// System.out.println(bill.getDhy());
// }
// }
}
}
|
单元测试-Junit-Service层 |
单元测试-junit |
|
package com.tdtech.cps.test.servicetest;
import java.io.File;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.tdtech.cps.service.ProjectReconService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext-*.xml" })
public class TestProjectReconSserviceImpl {
@Autowired
private ProjectReconService projectReconServiceImpl;
// @Autowired
// private ProjectReconDao projectReconDaoImpl;
// @Autowired
//// private HibernateTemplate hibernateTemplate;
/**
* 测试导入的配置清单
*
*/
@Test
public void importExcel() throws Exception{
File file = new File(
"d://upload//工勘模板.xlsx");
this.projectReconServiceImpl.importProjectRecon(file, 5,11);
}
/**
* 查询
*/
@Test
public void find() throws Exception{
this.projectReconServiceImpl.findProjectReconList(6, 12);
}
//
// public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
// this.hibernateTemplate = hibernateTemplate;
// }
public ProjectReconService getProjectReconServiceImpl() {
return projectReconServiceImpl;
}
public void setProjectReconServiceImpl(
ProjectReconService projectReconServiceImpl) {
this.projectReconServiceImpl = projectReconServiceImpl;
}
// public HibernateTemplate getHibernateTemplate() {
// return hibernateTemplate;
// }
//
// public ProjectReconDao getProjectReconDaoImpl() {
// return projectReconDaoImpl;
// }
// public void setProjectReconDaoImpl(ProjectReconDao projectReconDaoImpl) {
// this.projectReconDaoImpl = projectReconDaoImpl;
// }
}
|
<s:action>标签的使用 |
<s:action>标签的使用 |
|
<s:action name="cpsContract!findContractRefSells" namespace="/" var="cpsContractAction" >
<s:param name="contractid" >${param.contract_id }</s:param>
</s:action>
<!-- 输入工勘信息 -->
<br>
<br>
<br>
<div align="center">
<table style="width:30%;" border="1">
<tr>
<td>合同号: </td>
<td colspan="3">${param.contract_id }</td>
</tr>
<tr>
<td colspan="4">网元: </td>
</tr>
<s:iterator var="sellClass" value="#cpsContractAction.sellClasses">
<tr>
<td width="25%;"> </td>
<td width="25%;"><span style="color:blue;font-weight:bold;">${sellClass.name} ${cpsContractAction.ttr_id}</span><%-- <s:property value="#sellClass.name" /> --%>
<input type="hidden" value="${sellClass.sell_id}" />
</td>
<td width="25%;"><a href="inputProjectRecon.jsp?sellClassName=${sellClass.name}&contract_id=${param.contract_id}&sell_id=${sellClass.sell_id}&ttr_id=${cpsContractAction.ttr_id}">输入工勘</a></td>
<td width="25%;"><a href="">导出清单</a></td>
</tr>
</s:iterator>
</table>
</div>
|
从word模板生成word文件 |
从word模板生成word文件 |
|
package com.poi.util.word;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
/**
* 从模板生成word
*/
public class WordDemo_2 {
public static void main(String[] args) throws Exception{
//读取word模板
FileInputStream in = new FileInputStream(new File("d:\\test\\word_template.docx"));
XWPFDocument hdt = new XWPFDocument(in);
XWPFTable table = hdt.getTables().get(0);
List<XWPFTableRow> rows = table.getRows();
//读取表格行
for(int i=0;i<rows.size();i++){
XWPFTableRow row = rows.get(i);
switch(i){
case 0:
row.getCell(1).setText("网络");
break;
case 1:
row.getCell(1).setText("电路图");
break;
case 2:
row.getCell(1).setText("使用频率");
break;
case 3: //备注
row.getCell(1).setText("暂无备注");
break;
default :
break;
}
}
File f = new File("d:\\test\\genDoc.docx");
if(f.exists()){
f.delete();
}
BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream("d:\\test\\genDoc.docx",true));
ostream.toString().getBytes("UTF-8");
hdt.write(ostream);
//输出字节流
ostream.flush();
ostream.close();
}
}
2.word模板文件为: word_template.docx,表格为2列
文档
产品信息:
IPD信息:
决策评审点:
备注:
对应的编码:
名称:
标题:
原作者:
部门:
语言:
密级:
生命周期:
摘要(中文):
摘要(英文):
|
文件下载页面 |
文件下载页面 |
|
文件下载页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'error.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1>error</h1>
<SCRIPT LANGUAGE="JavaScript">
function returnPrePage(){
history.go(-1);
}
</SCRIPT>
<a href="#" onclick="javascript:returnPrePage();">返回前一页</a>
</body>
</html>
|
文件下载Action |
文件下载action |
|
文件下载Action
package com.tdtech.pdm.download;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class DownloadFileAction extends ActionSupport{
public String getUploadFileName() throws Exception{
String uploadFileName=ServletActionContext.getRequest().getParameter("uploadFileName");
return uploadFileName;
}
public InputStream getTargetFile() throws Exception{
String uploadFileName=ServletActionContext.getRequest().getParameter("uploadFileName");
System.out.println("下载Action-"+uploadFileName);
return new FileInputStream(new File("d:\\upload\\"+uploadFileName));
}
public String downloadFine() throws Exception{
return SUCCESS;
}
}
|
文件上传Action |
文件上传action |
|
文件上传Action
package com.tdtech.pdm.upload;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.tdtech.pdm.create.pojo.DQAssemblyPojo;
public class CommonUploadFileAction extends ActionSupport{
/**
* 文件上传属性
*/
private File uploadCommon;
private String uploadCommonContentType;
private String uploadCommonFileName;
private String savePath;
//跳转的页面
private String jumpPage;
private String dqcode;
/**
* 上传文件方法
*/
public String uploadFile() throws Exception{
System.out.println("CommonUploadFileAction.java-uploadFile():"+dqcode);
String targetDirectory="d:\\upload";
if(uploadCommonFileName==null || "".equals(uploadCommonFileName.trim())){
this.addFieldError("upload", "文件不能为空!");
}else{
String targetFileName=dqcode+"_"+uploadCommonFileName;
System.out.println("上传文件名为:"+uploadCommonFileName);
this.setSavePath(targetDirectory+"\\"+targetFileName); //设置文件保存路径
File target=new File(targetDirectory,dqcode+"_"+uploadCommonFileName);
HttpServletRequest request = ServletActionContext.getRequest();
try{
FileUtils.copyFile(uploadCommon,target);
return this.handlerJumpPage(request, this.jumpPage);
}catch(Exception e){
e.printStackTrace();
return this.handlerJumpPage(request, this.jumpPage);
}
}
return "input";
}
public String handlerJumpPage(HttpServletRequest request,String jumpPage){
HttpSession session = request.getSession();
List<DQAssemblyPojo> list =(List<DQAssemblyPojo>) session.getAttribute("assemblys");
List<DQAssemblyPojo> assemblys=new ArrayList<DQAssemblyPojo>();
for(int i=0;i<list.size();i++){
DQAssemblyPojo d = list.get(i);
System.out.println("遍历的上传文件名:"+d.getNcdocument());
if(d.getDqcode().equals(this.dqcode)){
d.setNcdocument(d.getDqcode()+"_"+this.uploadCommonFileName);
}
assemblys.add(d);
}
// for(DQAssemblyPojo d:list){
// System.out.println("handlerJumpPage()方法获取的ncdocument="+d.getNcdocument());
// }
if(session.getAttribute("assemblys")!=null){
session.removeAttribute("assemblys");
session.setAttribute("assemblys", assemblys);
}else{
session.setAttribute("assemblys", assemblys);
}
if("uploadMateDemandStandardBook.jsp".equals(this.jumpPage.trim())){
request.setAttribute("uploadCommonFileName", uploadCommonFileName);
request.setAttribute("uploadResult", "上传成功");
request.setAttribute("uploadFlag_dqcode", dqcode);
return "uploadMateDemandStandardBook";
}else{
request.removeAttribute("uploadCommonFileName");
request.setAttribute("uploadResult", "上传失败");
request.removeAttribute("uploadFlag_dqcode");
return "input";
}
}
/**
* setter与getter方法
*/
public File getUploadCommon() {
return uploadCommon;
}
public void setUploadCommon(File uploadCommon) {
this.uploadCommon = uploadCommon;
}
public String getUploadCommonContentType() {
return uploadCommonContentType;
}
public void setUploadCommonContentType(String uploadCommonContentType) {
this.uploadCommonContentType = uploadCommonContentType;
}
public String getUploadCommonFileName() {
return uploadCommonFileName;
}
public void setUploadCommonFileName(String uploadCommonFileName) {
this.uploadCommonFileName = uploadCommonFileName;
}
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String getJumpPage() {
return jumpPage;
}
public void setJumpPage(String jumpPage) {
this.jumpPage = jumpPage;
}
public String getDqcode() {
return dqcode;
}
public void setDqcode(String dqcode) {
this.dqcode = dqcode;
}
}
|
struts.xml |
struts.xml |
|
1.struts.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 将struts2的Action交给Spring管理 -->
<constant name="struts.objectFactory" value="spring" />
<!-- 配置其他常量 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 配置包 -->
<package name="struts-cps" extends="struts-default" namespace="/treeMenu">
<!-- 查询树形菜单Action -->
<action name="menuTree" class="com.tdtech.pdm.create.action.QueryTreeAction"></action>
<action name="partinfoTree" class="com.tdtech.pdm.functionmap.action.QueryPartinfoTreeAction"></action>
<action name="goodsinfoTree" class="com.tdtech.pdm.create.action.GoodsinfoTreeAction"></action>
<action name="createApproveUnderwrite" class="com.tdtech.pdm.create.action.CreateApproveUnderwriteAction"></action>
</package>
<!-- 下载文件Action配置 -->
<package name="download-cps" extends="struts-default" namespace="/download">
<action name="downloadFileAction" class="com.tdtech.pdm.download.DownloadFileAction">
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">targetFile</param>
<param name="contentDisposition">attachment;filename="${uploadFileName}"</param>
<param name="bufferSize">2048</param>
</result>
</action>
</package>
<!-- 创建模块中的Action的配置 -->
<package name="struts_ceate" extends="struts-default" namespace="/create">
<action name="goodsinfoTree" class="com.tdtech.pdm.create.action.GoodsinfoTreeAction"></action>
<action name="dQDocument" class="dQDocumentAction">
<result name="uploadFile" type="redirect">../create/createDQDocument.jsp</result>
<result name="createDQDocument" type="redirect">/cmmi/createApproveUnderwrite.jsp</result>
<result name="pageDQDocument">../showDocumentinfo.jsp</result>
<result name="queryDQDocumentById">/success.jsp</result>
<result name="deleteDQDocumentById">/success.jsp</result>
<result name="updateDQDocument">/success.jsp</result>
<result name="input">/error.jsp</result>
</action>
<action name="dQAssembly" class="dQAssemblyAction">
<result name="addDQAssembly">/create/showCreateAssembly.jsp</result>
<result name="deleteDQAssembly">/success.jsp</result>
<result name="updateDQAssembly">/success.jsp</result>
<result name="queryAllDQAssembly">/success.jsp</result>
<result name="queryDQAssemblyById">/success.jsp</result>
<result name="queryDQAssemblyByName">/success.jsp</result>
<result name="input">/error.jsp</result>
<result name="generateHwcode">/test/showCode.jsp</result>
<result name="queryDQAssembly" type="redirect">/create/showQueryAssemblyInfo.jsp</result>
<result name="addItemInfo">/create/createDQDocument.jsp</result>
<result name="queryDQAssemblyByLike">/create/queryAssemblyResult.jsp</result>
<result name="addAssemblyRecord">/create/pcbDesignFlowApplyBill.jsp</result>
<result name="pcbDesignFlowApplyBill">/create/pcbDesignFlowApplyBill.jsp</result>
<result name="newProAndMetAppBill">/create/createNewProductAndMeterielAppBill.jsp</result>
</action>
<action name="handlerAssembly" class="handlerAssemblyAction"></action>
<action name="newMateAppBill" class="newMateAppBillAction">
<result name="createNewMateAppBill">/create/showNewMaterielAppInfo.jsp</result>
<result name="saveRoleUserInformation">/create/createNewProductAndMeterielAppBill.jsp</result>
<result name="queryMateDemandAppBillByApplyid">/create/fillMateDemandBaseInfo.jsp</result>
<result name="saveMateBaseInfo">/create/createMateDemandApply.jsp</result>
<result name="saveRelativeInfo">/create/createMateDemandApply.jsp</result>
<result name="fillMateDemandBaseInfo_jsp">/create/fillMateDemandBaseInfo.jsp</result>
<result name="uploadMateDemandStandardBook_jsp">/create/uploadMateDemandStandardBook.jsp</result>
<result name="queryNewMateAppBill_jsp">/create/queryNewMateAppBill.jsp</result>
<result name="queryRiskEvaluationBill_jsp">/create/queryRiskEvaluationBill.jsp</result>
<result name="success">/create/newMaterielValidate.jsp</result>
<result name="input">/error.jsp</result>
</action>
<action name="riskEvaluation" class="riskEvaluationAction">
<result name="technologyRiskEvaluation_jsp">/create/technologyRiskEvaluation.jsp</result>
</action>
<action name="commonUploadFile" class="commonUploadFileAction">
<result name="uploadMateDemandStandardBook">/create/uploadMateDemandStandardBook.jsp</result>
</action>
<action name="clearUtil" class="clearUtilAction"></action>
</package>
<!-- 工作空间模块的Action配置 -->
<package name="struts_jobspace" extends="struts-default" namespace="/jobspace">
<action name="applypdmpower" class="applypdmpowerAction">
<result name="input">/error.jsp</result>
</action>
</package>
<!-- 用户模块的Action配置 -->
<package name="struts_user" extends="struts-default" namespace="/user">
<action name="user" class="userAction">
<result name="success" type="redirect">/index.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>
|
struts2 上传文件大小设置--设置最大为300M |
struts2 上传文件大小设置 |
|
所在文件:struts.properties
struts.multipart.maxSize=314572800
|
DQAssemblyDaoImpl.java |
dqassemblydaoimpl.java |
|
package com.tdtech.pdm.create.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.tdtech.pdm.create.dao.DQAssemblyDao;
import com.tdtech.pdm.create.pojo.DQAssemblyPojo;
public class DQAssemblyDaoImpl implements DQAssemblyDao{
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
/**
* 风险评估时的部件更新
*/
public boolean updateRiskEvaluation(List<DQAssemblyPojo> list){
boolean flag=false;
SessionFactory sessionFactory=null;
Session session =null;
Transaction tx=null;
try{
sessionFactory=this.hibernateTemplate.getSessionFactory();
session = sessionFactory.openSession();
tx=session.beginTransaction();
for(DQAssemblyPojo d:list){
String hql="update DQAssemblyPojo d set d.riskgrade=?,d.risksort=?,d.riskdescrible=?,d.eludemeasureadvice=?,d.recallbill=? where d.id=?";
Query query = session.createQuery(hql);
query.setString(0, d.getRiskgrade());
query.setString(1, d.getRisksort());
query.setString(2, d.getRiskdescrible());
query.setString(3, d.getEludemeasureadvice());
query.setString(4, d.getRecallbill());
query.setInteger(5, d.getId());
query.executeUpdate();
}
tx.commit();
flag=true;
}catch(Exception e){
tx.rollback();
}finally{
session.close();
}
return flag;
}
/**
* 更新部件的部件状态和流程状态
*/
public boolean updateStatus(final String assemblystatus,final String status,final int mateId){
boolean flag = false;
int num=0;
try{
num = this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql = "update tb_dqassembly d "+
"set d.assemblystatus=?,d.status=? "+
"where d.nmabid=?";
Query query = session.createSQLQuery(sql);
query.setString(0, assemblystatus);
query.setString(1, status);
query.setInteger(2, mateId);
return query.executeUpdate();
}
});
}catch(Exception e){
e.printStackTrace();
}
if(num>0){
flag=true;
}
return flag;
}
/**
* 保存物料关联部件信息
*/
public boolean saveRelativeInfo(final List<DQAssemblyPojo> list){
boolean flag=false;
int count=0;
try{
count=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int num=0;
for(DQAssemblyPojo d:list){
String hql="update DQAssemblyPojo d set d.adecandtypeflag=?,d.adecribleandtype=?,d.iscomparedoc=?,d.ncdocument=?,d.digest=? where d.dqcode=?";
Query query=session.createQuery(hql);
query.setString(0, d.getAdecandtypeflag());
query.setString(1, d.getAdecribleandtype());
query.setString(2, d.getIscomparedoc());
query.setString(3, d.getNcdocument());
query.setString(4, d.getDigest());
query.setString(5, d.getDqcode());
query.executeUpdate();
num+=1;
}
return num;
}
});
}catch(Exception e){
e.printStackTrace();
}
if(count>0){
flag=true;
}
return flag;
}
/**
* 更新部件信息
*/
public boolean updateDQAssembly(final List<DQAssemblyPojo> list){
boolean flag=false;
int count=0;
try{
count=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int num=0;
for(int i=0;i<list.size();i++){
DQAssemblyPojo n=list.get(i);
String sql="update tb_dqassembly d set d.adviceworkshop=?,d.advicetype=?,d.lapserate=? where d.dqcode=?";
Query query=session.createSQLQuery(sql);
query.setString(0, n.getAdviceworkshop());
query.setString(1, n.getAdvicetype());
query.setString(2, n.getLapserate());
query.setString(3, n.getDqcode());
query.executeUpdate();
num+=1;
}
return num;
}
});
}catch(Exception e){
e.printStackTrace();
}
System.out.println("更新的行数:"+count);
if(count==list.size()){
flag=true;
}
return flag;
}
/**
* 创建鼎桥部件
* @param dQAssemblyPojo
* @return
*/
public boolean addDQAssembly(DQAssemblyPojo dQAssemblyPojo){
boolean flag=false;
try{
this.hibernateTemplate.save(dQAssemblyPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 删除鼎桥部件
* @param id
* @return
*/
public boolean deleteDQAssembly(int id){
boolean flag=false;
try{
DQAssemblyPojo dQAssemblyPojo = this.getHibernateTemplate().get(DQAssemblyPojo.class, id);
this.getHibernateTemplate().delete(dQAssemblyPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 修改鼎桥部件
* @param dQAssemblyPojo
* @return
*/
public boolean updateDQAssembly(DQAssemblyPojo dQAssemblyPojo){
boolean flag=false;
try{
this.getHibernateTemplate().update(dQAssemblyPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 修改鼎桥部件
*/
public boolean updateDQAssembly(final Integer id,final Integer newMateAppBillId){
System.out.println("修改鼎桥部件 id="+id+",nmabid="+newMateAppBillId);
boolean flag=false;
try{
int num=0;
num=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql="update tb_newMateAppBill set nmabid=? where id=?";
Query query=session.createSQLQuery(sql);
query.setInteger(0, newMateAppBillId);
query.setInteger(1, id);
return query.executeUpdate();
}
});
if(num>0){
flag=true;
}
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 查询所有的鼎桥部件
* @return
*/
public List<DQAssemblyPojo> queryAllDQAssembly(){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
try{
list=this.getHibernateTemplate().find("from DQAssemblyPojo a order by a.id desc");
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 通过id查询鼎桥部件
* @param id
* @return
*/
public DQAssemblyPojo queryDQAssemblyById(int id){
DQAssemblyPojo dQAssemblyPojo=new DQAssemblyPojo();
//System.out.println("通过id查询鼎桥部件: id="+id);
try{
dQAssemblyPojo=(DQAssemblyPojo)this.getHibernateTemplate().find("from DQAssemblyPojo a where a.id="+id).get(0);
}catch(Exception e){
e.printStackTrace();
}
//System.out.println("通过id查询鼎桥部件-"+dQAssemblyPojo.getDqcode());
return dQAssemblyPojo;
}
/**
* 模糊查询
* @param name
* @return
*/
public List<DQAssemblyPojo> queryDQAssemblyByName(final String name){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
try{
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from DQAssemblyPojo a where a.goods like ? order by a.id desc";
Query query=session.createQuery(hql);
query.setString(0, "%"+name+"%");
return query.list();
}
});
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 生成华为编码
*/
public String generateHwcode(final String code){
//System.out.println("dao------------------"+code);
String hwcode=null;
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
try{
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from DQAssemblyPojo a where a.hwcode like ? order by a.hwcode desc";
Query query=session.createQuery(hql);
query.setString(0, code+"%");
return query.list();
}
});
if(list.size()>0){
hwcode=list.get(0).getHwcode();
System.out.println("dao-华为编码为:"+hwcode);
}else{
hwcode=" ";
}
}catch(Exception e){
e.printStackTrace();
hwcode=" ";
}
StringBuffer s=new StringBuffer();
String currentHwcode=null;
int hwcodeInt=0;
if(hwcode!=null && (!(" ".equals(hwcode)))){
s=s.append(hwcode.substring(4));
hwcodeInt=Integer.parseInt(s.toString());
hwcodeInt+=1;
if(hwcodeInt<10){
currentHwcode=hwcode.substring(0,4)+"0000"+hwcodeInt;
}else if(hwcodeInt<100){
currentHwcode=hwcode.substring(0,4)+"000"+hwcodeInt;
}else if(hwcodeInt<1000){
currentHwcode=hwcode.substring(0,4)+"00"+hwcodeInt;
}else if(hwcodeInt<10000){
currentHwcode=hwcode.substring(0,4)+"0"+hwcodeInt;
}else{
currentHwcode=hwcode.substring(0,4)+hwcodeInt;
}
}else{
currentHwcode=code+"00001";
}
System.out.println("dao-生成华为编码-"+currentHwcode);
return currentHwcode;
}
/**
* 通过编码或名称模糊查询
*/
public List<DQAssemblyPojo> queryDQAssembly(final String dqcode,final String outtername){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql=null;
Query query=null;
if((dqcode==null && outtername==null) || ("".equals(dqcode) && "".equals(outtername))){
System.out.println("--------null -----null");
hql="from DQAssemblyPojo d order by d.id asc";
query=session.createQuery(hql);
query.setFirstResult(0);
query.setMaxResults(50);
return query.list();
}
if(dqcode!=null && outtername==null){
hql="from DQAssemblyPojo d where d.dqcode like ? order by d.dqcode asc";
query=session.createQuery(hql);
query.setString(0, "%"+dqcode+"%");
}else if(outtername!=null && dqcode==null){
hql="from DQAssemblyPojo d where d.outtername like ? order by d.dqcode asc";
query=session.createQuery(hql);
query.setString(0, "%"+outtername+"%");
}else if(dqcode!=null && outtername!=null){
hql="from DQAssemblyPojo d where d.dqcode like ? order by d.dqcode asc";
query=session.createQuery(hql);
query.setString(0, "%"+dqcode+"%");
}
return query.list();
}
});
if(list.size()>100){
return null;
}
return list;
}
/**
* 查询多个部件
*/
public List<DQAssemblyPojo> queryMultiAssemblyRecord(final int[] ids){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int len=ids.length;
String[] s=new String[len];
StringBuffer sb=new StringBuffer("from DQAssemblyPojo d where d.id in(");
for(int i=0;i<len;i++){
if(i==len-1){
sb.append("?");
}else{
sb.append("?"+",");
}
}
sb.append(")");
System.out.println(sb.toString());
Query query = session.createQuery(sb.toString());
for(int i=0;i<ids.length;i++){
query.setInteger(i, ids[i]);
}
return query.list();
}
});
return list;
}
}
|
DQDocumentDaoImpl.java |
dqdocumentdaoimpl.java |
|
package com.tdtech.pdm.create.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.tdtech.pdm.create.dao.DQDocumentDao;
import com.tdtech.pdm.create.pojo.DQDocumentPojo;
public class DQDocumentDaoImpl implements DQDocumentDao {
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
/**
* 创建鼎桥文档
*/
public boolean createDQDocument(DQDocumentPojo dQDocumentPojo){
//System.out.println("创建鼎桥文档-dao");
boolean flag=false;
try{
this.getHibernateTemplate().save(dQDocumentPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 查看所有的鼎桥文档
*/
public List<DQDocumentPojo> queryAllDQDocument(){
List<DQDocumentPojo> list=new ArrayList<DQDocumentPojo>();
String hql="from DQDocumentPojo d order by id asc";
try{
list=this.getHibernateTemplate().find(hql);
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 分页查询所有的鼎桥文档
*/
public List<DQDocumentPojo> queryPageDQDocument(final int currentPage,final int pageSize){
List<DQDocumentPojo> list=new ArrayList<DQDocumentPojo>();
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from DQDocumentPojo d order by d.id desc";
Query query = session.createQuery(hql);
query.setFirstResult((currentPage-1)*pageSize); //该参数为从第几条记录开始
query.setMaxResults(pageSize); //每页显示的记录数
return query.list();
}
});
return list;
}
/**
* 查看单个鼎桥文档
*/
public DQDocumentPojo queryDQDocumentById(int id){
DQDocumentPojo dQDocumentPojo=null;
String hql="from DQDocumentPojo d where d.id="+id;
try{
this.getHibernateTemplate().find(hql);
}catch(Exception e){
e.printStackTrace();
}
return dQDocumentPojo;
}
/**
* 删除鼎桥文档
*/
public boolean deleteDQDocumentById(final int id){
boolean flag=false;
try{
//System.out.println("开始");
DQDocumentPojo d=this.getHibernateTemplate().get(DQDocumentPojo.class, id);
this.getHibernateTemplate().delete(d);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 修改鼎桥文档
*/
public boolean updateDQDocument(DQDocumentPojo dQDocumentPojo){
System.out.println("修改鼎桥文档-dao");
boolean flag=false;
try{
this.getHibernateTemplate().update(dQDocumentPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 生成文档编码
*/
public String generateDocumentcode(){
String documentcode=null;
List<DQDocumentPojo> list=new ArrayList<DQDocumentPojo>();
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from DQDocumentPojo d where d.documentcode like ? order by d.documentcode desc";
Query query=session.createQuery(hql);
query.setString(0, "TD-010-%");
return query.list();
}
});
if(list.size()>0){
documentcode=list.get(0).getDocumentcode();
}else{
documentcode=" ";
}
StringBuffer s=new StringBuffer();
String newDocumentcode=null;
int currentS=0;
if(documentcode!=null && (!(" ".equals(documentcode)))){
s=s.append(documentcode.substring(7));
currentS=Integer.parseInt(s.toString());
currentS=currentS+1;
if(currentS<10){
newDocumentcode="TD-010-"+"0000"+currentS;
}else if(currentS<100){
newDocumentcode="TD-010-"+"000"+currentS;
}else if(currentS<1000){
newDocumentcode="TD-010-"+"00"+currentS;
}else if(currentS<10000){
newDocumentcode="TD-010-"+"0"+currentS;
}else{
newDocumentcode="TD-010-"+currentS;
}
}else{
newDocumentcode="TD-010-00001";
}
return newDocumentcode;
}
}
|
NewMateAppBillDaoImpl.java |
newmateappbilldaoimpl.java |
|
package com.tdtech.pdm.create.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.tdtech.pdm.create.dao.NewMateAppBillDao;
import com.tdtech.pdm.create.pojo.DQAssemblyPojo;
import com.tdtech.pdm.create.pojo.NewMateAppBillPojo;
public class NewMateAppBillDaoImpl implements NewMateAppBillDao{
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
/**
* 风险评估时的更新
*/
public boolean updateRiskEvaluation(final NewMateAppBillPojo newMateAppBillPojo){
boolean flag=false;
try{
int count=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql="update tb_newMateAppBill d "+
"set d.recallbill=? "+
"where d.applyid=?";
Query query = session.createSQLQuery(sql);
query.setString(0, newMateAppBillPojo.getRecallbill());
query.setString(1, newMateAppBillPojo.getApplyid());
return query.executeUpdate();
}
});
if(count>0){
flag=true;
}
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 通过applyid查询物料申请单的主键
*/
public int queryIdByApplyid(final String applyid){
int id=0;
try{
id=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql="select d.id from tb_newMateAppBill d where d.applyid=?";
Query query = session.createSQLQuery(sql);
query.setString(0, applyid);
return query.list().get(0);
}
});
}catch(Exception e){
e.printStackTrace();
}
System.out.println("通过applyid查询物料申请单的主键:id="+id);
return id;
}
/**
* 任务完成
*/
public boolean updateTaskComplate(final String applyid,final String applyResult,final String isYTechEnvalute,final String isYResearchValidate){
boolean flag = false;
int num=0; //受影响的行数
try{
num=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql = "update tb_newMateAppBill d "+
"set d.applyResult=?,d.isYTechEnvalute=?,d.isYResearchValidate=? "+
"where d.applyid=?";
Query query = session.createSQLQuery(sql);
query.setString(0, applyResult);
query.setString(1, isYTechEnvalute);
query.setString(2, isYResearchValidate);
query.setString(3, applyid);
return query.executeUpdate();
}
});
}catch(Exception e){
e.printStackTrace();
}
if(num>0){
flag=true;
}
return flag;
}
/**
* 更新物料申请单信息
*/
public boolean updateMateDemandAppBill(final NewMateAppBillPojo newMateAppBillPojo){
boolean flag=false;
try{
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int num=0;
String sql="update tb_newMateAppBill d "
+"set d.appbillname=?,d.projecttype=?,d.standprotime=?,"
+"d.cdcpplaintime=?,d.pdcpplaintime=?,d.tr4atime=?,d.productmanager=?,"
+"d.hardwaremanager=?,d.buyer=?,d.costmanager=?,"
+"d.sysmanager=?,d.projectmanager=?,d.roadsignedition=?,d.edition=? "
+"where d.applyid=?";
Query query=session.createSQLQuery(sql);
query.setString(0, newMateAppBillPojo.getAppbillname());
query.setString(1, newMateAppBillPojo.getProjecttype());
query.setString(2, newMateAppBillPojo.getStandprotime());
query.setString(3, newMateAppBillPojo.getCdcpplaintime());
query.setString(4, newMateAppBillPojo.getPdcpplaintime());
query.setString(5, newMateAppBillPojo.getTr4atime());
query.setString(6, newMateAppBillPojo.getProductmanager());
query.setString(7, newMateAppBillPojo.getHardwaremanager());
query.setString(8, newMateAppBillPojo.getBuyer());
query.setString(9, newMateAppBillPojo.getCostmanager());
query.setString(10, newMateAppBillPojo.getSysmanager());
query.setString(11, newMateAppBillPojo.getProjectmanager());
query.setString(12, newMateAppBillPojo.getRoadsignedition());
query.setString(13, newMateAppBillPojo.getEdition());
query.setString(14, newMateAppBillPojo.getApplyid());
query.executeUpdate();
num+=1;
return num;
}
});
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 通过申请单编号查询物料认证申请单--精确查询
*/
public NewMateAppBillPojo queryMateDemandAppBillByApplyid(final String applyid){
NewMateAppBillPojo n=new NewMateAppBillPojo();
List<NewMateAppBillPojo> list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from NewMateAppBillPojo n where applyid='"+applyid+"'";
Query query = session.createQuery(hql);
return query.list();
}
});
System.out.println("NewMateAppBillDaoImpl.java,method=queryMateDemandAppBillByApplyid()通过申请单编号查询物料认证申请单--dao--精确查询"+list.size());
if(list.size()>0){
n=list.get(0);
}
return n;
}
/**
* 查询多个新物料认证申请单
*/
public List<NewMateAppBillPojo> queryMutiNewMateAppBill(final String applyid){
List<NewMateAppBillPojo> list=new ArrayList<NewMateAppBillPojo>();
try{
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from NewMateAppBillPojo n where n.applyid like ? order by n.applyid desc";
Query query = session.createQuery(hql);
query.setString(0, "%"+applyid+"%");
return query.list();
}
});
//System.out.println("------------size="+list.size());
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 查询最新的新物件认证申请单
*/
public List<NewMateAppBillPojo> queryNewMateAppBill(){
List<NewMateAppBillPojo> list=new ArrayList<NewMateAppBillPojo>();
try{
list=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql="select * from tb_newMateAppBill m where m.id=(select max(t.id) from tb_newMateAppBill t)";
Query query = session.createSQLQuery(sql).addEntity(NewMateAppBillPojo.class);
return query.list();
}
});
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 创建新物料认证申请单
*/
public boolean createNewMateAppBill(NewMateAppBillPojo newMateAppBillPojo){
boolean flag=false;
try{
this.hibernateTemplate.save(newMateAppBillPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 生成申请单编号
*/
public String generateAppBillCode(final String smallSortCode){
// System.out.println("dao-生成新物料认证申请单编号 smallSortCode="+smallSortCode);
String applyid=null;
List<NewMateAppBillPojo> list=new ArrayList<NewMateAppBillPojo>();
try{
list=this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from NewMateAppBillPojo np where np.applyid like 'MAB-"+smallSortCode+"%' order by np.applyid desc";
Query query=session.createQuery(hql);
return query.list();
}
});
}catch(Exception e){
applyid=" ";
}
// System.out.println("生成申请单编号 size="+list.size());
if(list.size()>0){
applyid=list.get(0).getApplyid();
// System.out.println("当前申请单编号:"+applyid);
}else{
applyid=" ";
}
if(!(" ".equals(applyid))){
String s=applyid.substring(8);
StringBuffer sb=new StringBuffer();
int applyNum=Integer.parseInt(s);
applyNum+=1;
if(applyNum<10){
sb.append("0000"+applyNum);
}else if(applyNum<100){
sb.append("000"+applyNum);
}else if(applyNum<1000){
sb.append("00"+applyNum);
}else if(applyNum<10000){
sb.append("0"+applyNum);
}else{
sb.append(applyNum);
}
// System.out.println("生成的物料申请单号:"+applyNum);
System.out.println("生成完整的物料申请单号:"+"MAB-"+smallSortCode+sb.toString());
return "MAB-"+smallSortCode+sb.toString();
}else{
System.out.println("物料申请单号:"+smallSortCode+"00001");
return "MAB-"+smallSortCode+"00001";
}
}
}
|
Hibernate批处理action |
hibernate批处理action |
|
package com.tdtech.pdm.create.action;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.tdtech.pdm.create.pojo.DQAssemblyPojo;
import com.tdtech.pdm.create.pojo.NewMateAppBillPojo;
import com.tdtech.pdm.create.service.DQAssemblyService;
import com.tdtech.pdm.create.service.NewMateAppBillService;
import com.tdtech.pdm.create.service.RiskEvaluationService;
@SuppressWarnings("serial")
public class RiskEvaluationAction extends ActionSupport{
/**
* DQAssemblyPojo的属性
*/
// private Integer assemblyId; //DQAssemblyPojo的对象标示符--对应部件表中相应记录的主键
// private String riskgrade; //风险等级--2013-4-12
// private String risksort; //风险类别--2013-4-12
// private String riskdescrible; //风险描述--2013-4-12
// private String eludemeasureadvice; //规避措施建议--2013-4-12
// private String assemblyRecallbill; //撤单--2013-4-12
/**
* NewMateAppBillPojo的属性
*/
private Integer mateId; //NewMateAppBillPojo的对象标示符--对应物料申请单表中记录的主键
private String applyid; //物料申请单编号
private String mateRecallbill; //撤单--2013-4-12
/**
* 依赖注入属性
*/
private RiskEvaluationService riskEvaluationServiceImpl;
private NewMateAppBillService newMateAppBillServiceImpl;
private DQAssemblyService dQAssemblyServiceImpl;
/**
* 保存风险评估单信息
*/
public String saveRiskEvaluation() throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
System.out.println("action execute method is:com.tdtech.pdm.create.action.RiskEvaluationAction's saveRiskEvaluation().");
String[] assemblyIds = request.getParameterValues("assemblyId");
String[] riskgrades = request.getParameterValues("riskgrade");
String[] risksorts = request.getParameterValues("risksort");
String[] riskdescribles =request.getParameterValues("riskdescrible");
String[] eludemeasureadvices = request.getParameterValues("eludemeasureadvice");
//String[] assemblyRecallbills = request.getParameterValues("assemblyRecallbill");
int len = assemblyIds.length;
DQAssemblyPojo d = null;
List<DQAssemblyPojo> assemblys = new ArrayList<DQAssemblyPojo>();
for(int i=0;i<len;i++){
d = new DQAssemblyPojo();
d.setId(Integer.parseInt(assemblyIds[i]));
d.setRiskgrade(riskgrades[i]);
d.setRisksort(risksorts[i]);
d.setRiskdescrible(riskdescribles[i]);
d.setEludemeasureadvice(eludemeasureadvices[i]);
assemblys.add(d);
}
NewMateAppBillPojo newMateAppBillPojo = new NewMateAppBillPojo();
//newMateAppBillPojo.setId(mateId);
newMateAppBillPojo.setApplyid(applyid);
newMateAppBillPojo.setRecallbill(mateRecallbill);
boolean nFlag = this.getNewMateAppBillServiceImpl().updateRiskEvaluation(newMateAppBillPojo);
boolean dFlag = false;
if(nFlag){
System.out.println("更新物料申请成功");
dFlag = this.getdQAssemblyServiceImpl().updateRiskEvaluation(assemblys);
}else{
System.out.println("更新物料申请失败");
}
if(dFlag){
System.out.println("更新部件成功");
}else{
System.out.println("更新部件失败");
}
if(!dFlag || !nFlag){
System.out.println("保存失败");
out.print("保存失败");
}else{
System.out.println("保存成功");
out.print("保存成功");
}
if(dFlag){
System.out.println("保存成功");
out.print("保存成功");
}else{
System.out.println("保存失败");
out.print("保存失败");
}
return null;
}
/**
* 查询最新的风险评估单
*/
public String queryLastestRiskEvalution() throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
String mateapplyid = request.getParameter("mateapplyid");
System.out.println("查询最新的风险评估单-mateapplyid="+mateapplyid);
NewMateAppBillPojo newMateAppBillPojo = this.newMateAppBillServiceImpl.queryMateDemandAppBillByApplyid(mateapplyid);
Set<DQAssemblyPojo> set = newMateAppBillPojo.getdQAssemblys();
DQAssemblyPojo[] list=new DQAssemblyPojo[set.size()];
int i=0;
int[] ids=new int[set.size()];
for(DQAssemblyPojo d:set){
list[i]=d;
ids[i]=d.getId();
i=i+1;
}
Arrays.sort(ids);
List<DQAssemblyPojo> assemblys=new ArrayList<DQAssemblyPojo>();
for(int j=0;j<ids.length;j++){
for(DQAssemblyPojo d:list){
if(d.getId()==ids[j]){
assemblys.add(d);
}
}
}
request.setAttribute("newMateAppBillPojo", newMateAppBillPojo);
request.setAttribute("assemblys", assemblys);
return "technologyRiskEvaluation_jsp";
}
public String getApplyid() {
return applyid;
}
public void setApplyid(String applyid) {
this.applyid = applyid;
}
// public Integer getAssemblyId() {
// return assemblyId;
// }
// public void setAssemblyId(Integer assemblyId) {
// this.assemblyId = assemblyId;
// }
// public String getRiskgrade() {
// return riskgrade;
// }
// public void setRiskgrade(String riskgrade) {
// this.riskgrade = riskgrade;
// }
// public String getRisksort() {
// return risksort;
// }
// public void setRisksort(String risksort) {
// this.risksort = risksort;
// }
// public String getRiskdescrible() {
// return riskdescrible;
// }
// public void setRiskdescrible(String riskdescrible) {
// this.riskdescrible = riskdescrible;
// }
// public String getEludemeasureadvice() {
// return eludemeasureadvice;
// }
// public void setEludemeasureadvice(String eludemeasureadvice) {
// this.eludemeasureadvice = eludemeasureadvice;
// }
// public String getAssemblyRecallbill() {
// return assemblyRecallbill;
// }
// public void setAssemblyRecallbill(String assemblyRecallbill) {
// this.assemblyRecallbill = assemblyRecallbill;
// }
public Integer getMateId() {
return mateId;
}
public void setMateId(Integer mateId) {
this.mateId = mateId;
}
public String getMateRecallbill() {
return mateRecallbill;
}
public void setMateRecallbill(String mateRecallbill) {
this.mateRecallbill = mateRecallbill;
}
public RiskEvaluationService getRiskEvaluationServiceImpl() {
return riskEvaluationServiceImpl;
}
public void setRiskEvaluationServiceImpl(
RiskEvaluationService riskEvaluationServiceImpl) {
this.riskEvaluationServiceImpl = riskEvaluationServiceImpl;
}
public NewMateAppBillService getNewMateAppBillServiceImpl() {
return newMateAppBillServiceImpl;
}
public void setNewMateAppBillServiceImpl(
NewMateAppBillService newMateAppBillServiceImpl) {
this.newMateAppBillServiceImpl = newMateAppBillServiceImpl;
}
public DQAssemblyService getdQAssemblyServiceImpl() {
return dQAssemblyServiceImpl;
}
public void setdQAssemblyServiceImpl(DQAssemblyService dQAssemblyServiceImpl) {
this.dQAssemblyServiceImpl = dQAssemblyServiceImpl;
}
}
|
Hibernate批处理pojo类 |
hibernate批处理pojo类 |
|
package com.tdtech.pdm.create.pojo;
import java.io.Serializable;
/**
* 鼎桥部件Pojo类--对应表tb_dqassembly
* @author tWX162737
*
*/
public class DQAssemblyPojo implements Serializable {
private Integer id; //主键
private String hwcode; //华为编码
private String dqcode; //鼎桥编码
private String goodsline; //产品线
private String goods; //产品
private String defaultunit; //默认单位
private String resource; //来源
private String template; //模板
private String organise; //组织
private String lifetime; //生命周期
private String smallSortCode;
private String machinetype;
private String parttype;
private String bantype;
private String innertype;
private String outtername;
private String outterenname;
private String drawingedition;
private String isenvironment;
private String isnobittern;
private String tackexplain;
private String sortteanname; //分类组名--2013-3-22
private String smallsortname; //小类名称--2013-3-22 14:14
private String author; //作者--2013-3-22
private String edition ; //版本--2013-3-22
private String status ; //流程状态--2013-3-22
private String assemblystatus ; //部件状态--2013-3-22 14:14
private String instance ; //状况--2013-3-22 14:14
private String createtime ; //创建时间--2013-3-22 14:14
private String lastupdatetime ; //上次修改时间--2013-3-22 14:14
private String updateperson ; //修改者--2013-3-22 14:14
private String sortinfo ; //分类信息--2013-3-22 14:14
private Integer pintotal; //PIN总数--2013-3-25 9:24
private Integer layercount; //层数--2013-3-25 9:24
private String workshoptypeflag ; //厂家型号标识--2013-3-25 9:24
private String serialmode ; //工艺组装方式--2013-3-25 9:24
private String plyscale ; //厚径比--2013-3-25 9:24
private String spellboard ; //拼版信息--2013-3-25 9:24
private String isbackboard ; //是否背板--2013-3-25 9:24
private String isequipment; //是否存在压接器件--2013-3-25 9:24
private String isflagboard; //是否射频板--2013-3-25 9:24
private String isplumbum; //是否无铅--2013-3-25 9:24
private String ispedance; //是否阻抗控制--2013-3-25 9:24
private String standlevel; //适用的刚性印制板检验标准等级--2013-3-25 9:24
private String especialart; //特殊工艺--2013-3-25 9:24
private String especialask; //特殊要求--2013-3-25 9:24
private String outtypesize; //外型尺寸--2013-3-25 9:24
private Integer broachaccount; //钻孔总数--2013-3-25 9:24
private Float minaperture; //最小孔径--2013-3-25 9:24
private Float minspace; //最小线间距--2013-3-25 9:24
private Float minwidth; //最小线宽--2013-3-25 9:24
private String endecrible; //英文描述--2013-3-25 9:24
private String adviceworkshop; //建议厂家--2013-4-7
private String advicetype; //建议类型--2013-4-7
private String lapserate; //失效率--2013-4-7
private String adecandtypeflag; //部件编码/厂家型号标识 --2013-4-8
private String adecribleandtype; //部件描述/厂家型号--2013-4-8
private String iscomparedoc; //是否有参考文档--2013-4-8
private String ncdocument; //新建参考文档名称--2013-4-8
private String digest; //摘要--2013-4-8
private String riskgrade; //风险等级--2013-4-12
private String risksort; //风险类别--2013-4-12
private String riskdescrible; //风险描述--2013-4-12
private String eludemeasureadvice; //规避措施建议--2013-4-12
private String recallbill; //撤单--2013-4-12
private NewMateAppBillPojo newMateAppBill; //对应一个物料认证申请单
public DQAssemblyPojo() {
}
public DQAssemblyPojo(Integer id, String hwcode, String dqcode,
String goodsline, String goods, String defaultunit,
String resource, String template, String organise, String lifetime,
String smallSortCode, String machinetype, String parttype,
String bantype, String innertype, String outtername,
String outterenname, String drawingedition, String isenvironment,
String isnobittern, String tackexplain, String sortteanname,
String smallsortname, String author, String edition, String status,
String assemblystatus, String instance, String createtime,
String lastupdatetime, String updateperson, String sortinfo,
Integer pintotal, Integer layercount, String workshoptypeflag,
String serialmode, String plyscale, String spellboard,
String isbackboard, String isequipment, String isflagboard,
String isplumbum, String ispedance, String standlevel,
String especialart, String especialask, String outtypesize,
Integer broachaccount, Float minaperture, Float minspace,
Float minwidth, String endecrible, String adviceworkshop,
String advicetype, String lapserate, String adecandtypeflag,
String adecribleandtype, String iscomparedoc, String ncdocument,
String digest, String riskgrade, String risksort,
String riskdescrible, String eludemeasureadvice, String recallbill,
NewMateAppBillPojo newMateAppBill) {
this.id = id;
this.hwcode = hwcode;
this.dqcode = dqcode;
this.goodsline = goodsline;
this.goods = goods;
this.defaultunit = defaultunit;
this.resource = resource;
this.template = template;
this.organise = organise;
this.lifetime = lifetime;
this.smallSortCode = smallSortCode;
this.machinetype = machinetype;
this.parttype = parttype;
this.bantype = bantype;
this.innertype = innertype;
this.outtername = outtername;
this.outterenname = outterenname;
this.drawingedition = drawingedition;
this.isenvironment = isenvironment;
this.isnobittern = isnobittern;
this.tackexplain = tackexplain;
this.sortteanname = sortteanname;
this.smallsortname = smallsortname;
this.author = author;
this.edition = edition;
this.status = status;
this.assemblystatus = assemblystatus;
this.instance = instance;
this.createtime = createtime;
this.lastupdatetime = lastupdatetime;
this.updateperson = updateperson;
this.sortinfo = sortinfo;
this.pintotal = pintotal;
this.layercount = layercount;
this.workshoptypeflag = workshoptypeflag;
this.serialmode = serialmode;
this.plyscale = plyscale;
this.spellboard = spellboard;
this.isbackboard = isbackboard;
this.isequipment = isequipment;
this.isflagboard = isflagboard;
this.isplumbum = isplumbum;
this.ispedance = ispedance;
this.standlevel = standlevel;
this.especialart = especialart;
this.especialask = especialask;
this.outtypesize = outtypesize;
this.broachaccount = broachaccount;
this.minaperture = minaperture;
this.minspace = minspace;
this.minwidth = minwidth;
this.endecrible = endecrible;
this.adviceworkshop = adviceworkshop;
this.advicetype = advicetype;
this.lapserate = lapserate;
this.adecandtypeflag = adecandtypeflag;
this.adecribleandtype = adecribleandtype;
this.iscomparedoc = iscomparedoc;
this.ncdocument = ncdocument;
this.digest = digest;
this.riskgrade = riskgrade;
this.risksort = risksort;
this.riskdescrible = riskdescrible;
this.eludemeasureadvice = eludemeasureadvice;
this.recallbill = recallbill;
this.newMateAppBill = newMateAppBill;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getHwcode() {
return hwcode;
}
public void setHwcode(String hwcode) {
this.hwcode = hwcode;
}
public String getDqcode() {
return dqcode;
}
public void setDqcode(String dqcode) {
this.dqcode = dqcode;
}
public String getGoodsline() {
return goodsline;
}
public void setGoodsline(String goodsline) {
this.goodsline = goodsline;
}
public String getGoods() {
return goods;
}
public void setGoods(String goods) {
this.goods = goods;
}
public String getDefaultunit() {
return defaultunit;
}
public void setDefaultunit(String defaultunit) {
this.defaultunit = defaultunit;
}
public String getResource() {
return resource;
}
public void setResource(String resource) {
this.resource = resource;
}
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
public String getOrganise() {
return organise;
}
public void setOrganise(String organise) {
this.organise = organise;
}
public String getLifetime() {
return lifetime;
}
public void setLifetime(String lifetime) {
this.lifetime = lifetime;
}
public String getSmallSortCode() {
return smallSortCode;
}
public void setSmallSortCode(String smallSortCode) {
this.smallSortCode = smallSortCode;
}
public String getMachinetype() {
return machinetype;
}
public void setMachinetype(String machinetype) {
this.machinetype = machinetype;
}
public String getParttype() {
return parttype;
}
public void setParttype(String parttype) {
this.parttype = parttype;
}
public String getBantype() {
return bantype;
}
public void setBantype(String bantype) {
this.bantype = bantype;
}
public String getInnertype() {
return innertype;
}
public void setInnertype(String innertype) {
this.innertype = innertype;
}
public String getOuttername() {
return outtername;
}
public void setOuttername(String outtername) {
this.outtername = outtername;
}
public String getOutterenname() {
return outterenname;
}
public void setOutterenname(String outterenname) {
this.outterenname = outterenname;
}
public String getDrawingedition() {
return drawingedition;
}
public void setDrawingedition(String drawingedition) {
this.drawingedition = drawingedition;
}
public String getIsenvironment() {
return isenvironment;
}
public void setIsenvironment(String isenvironment) {
this.isenvironment = isenvironment;
}
public String getIsnobittern() {
return isnobittern;
}
public void setIsnobittern(String isnobittern) {
this.isnobittern = isnobittern;
}
public String getTackexplain() {
return tackexplain;
}
public void setTackexplain(String tackexplain) {
this.tackexplain = tackexplain;
}
public String getSortteanname() {
return sortteanname;
}
public void setSortteanname(String sortteanname) {
this.sortteanname = sortteanname;
}
public String getSmallsortname() {
return smallsortname;
}
public void setSmallsortname(String smallsortname) {
this.smallsortname = smallsortname;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
this.edition = edition;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getAssemblystatus() {
return assemblystatus;
}
public void setAssemblystatus(String assemblystatus) {
this.assemblystatus = assemblystatus;
}
public String getInstance() {
return instance;
}
public void setInstance(String instance) {
this.instance = instance;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public String getLastupdatetime() {
return lastupdatetime;
}
public void setLastupdatetime(String lastupdatetime) {
this.lastupdatetime = lastupdatetime;
}
public String getUpdateperson() {
return updateperson;
}
public void setUpdateperson(String updateperson) {
this.updateperson = updateperson;
}
public String getSortinfo() {
return sortinfo;
}
public void setSortinfo(String sortinfo) {
this.sortinfo = sortinfo;
}
public Integer getPintotal() {
return pintotal;
}
public void setPintotal(Integer pintotal) {
this.pintotal = pintotal;
}
public Integer getLayercount() {
return layercount;
}
public void setLayercount(Integer layercount) {
this.layercount = layercount;
}
public String getWorkshoptypeflag() {
return workshoptypeflag;
}
public void setWorkshoptypeflag(String workshoptypeflag) {
this.workshoptypeflag = workshoptypeflag;
}
public String getSerialmode() {
return serialmode;
}
public void setSerialmode(String serialmode) {
this.serialmode = serialmode;
}
public String getPlyscale() {
return plyscale;
}
public void setPlyscale(String plyscale) {
this.plyscale = plyscale;
}
public String getSpellboard() {
return spellboard;
}
public void setSpellboard(String spellboard) {
this.spellboard = spellboard;
}
public String getIsbackboard() {
return isbackboard;
}
public void setIsbackboard(String isbackboard) {
this.isbackboard = isbackboard;
}
public String getIsequipment() {
return isequipment;
}
public void setIsequipment(String isequipment) {
this.isequipment = isequipment;
}
public String getIsflagboard() {
return isflagboard;
}
public void setIsflagboard(String isflagboard) {
this.isflagboard = isflagboard;
}
public String getIsplumbum() {
return isplumbum;
}
public void setIsplumbum(String isplumbum) {
this.isplumbum = isplumbum;
}
public String getIspedance() {
return ispedance;
}
public void setIspedance(String ispedance) {
this.ispedance = ispedance;
}
public String getStandlevel() {
return standlevel;
}
public void setStandlevel(String standlevel) {
this.standlevel = standlevel;
}
public String getEspecialart() {
return especialart;
}
public void setEspecialart(String especialart) {
this.especialart = especialart;
}
public String getEspecialask() {
return especialask;
}
public void setEspecialask(String especialask) {
this.especialask = especialask;
}
public String getOuttypesize() {
return outtypesize;
}
public void setOuttypesize(String outtypesize) {
this.outtypesize = outtypesize;
}
public Integer getBroachaccount() {
return broachaccount;
}
public void setBroachaccount(Integer broachaccount) {
this.broachaccount = broachaccount;
}
public Float getMinaperture() {
return minaperture;
}
public void setMinaperture(Float minaperture) {
this.minaperture = minaperture;
}
public Float getMinspace() {
return minspace;
}
public void setMinspace(Float minspace) {
this.minspace = minspace;
}
public Float getMinwidth() {
return minwidth;
}
public void setMinwidth(Float minwidth) {
this.minwidth = minwidth;
}
public String getEndecrible() {
return endecrible;
}
public void setEndecrible(String endecrible) {
this.endecrible = endecrible;
}
public NewMateAppBillPojo getNewMateAppBill() {
return newMateAppBill;
}
public void setNewMateAppBill(NewMateAppBillPojo newMateAppBill) {
this.newMateAppBill = newMateAppBill;
}
public String getAdviceworkshop() {
return adviceworkshop;
}
public void setAdviceworkshop(String adviceworkshop) {
this.adviceworkshop = adviceworkshop;
}
public String getAdvicetype() {
return advicetype;
}
public void setAdvicetype(String advicetype) {
this.advicetype = advicetype;
}
public String getLapserate() {
return lapserate;
}
public void setLapserate(String lapserate) {
this.lapserate = lapserate;
}
public String getNcdocument() {
return ncdocument;
}
public void setNcdocument(String ncdocument) {
this.ncdocument = ncdocument;
}
public String getAdecribleandtype() {
return adecribleandtype;
}
public void setAdecribleandtype(String adecribleandtype) {
this.adecribleandtype = adecribleandtype;
}
public String getIscomparedoc() {
return iscomparedoc;
}
public void setIscomparedoc(String iscomparedoc) {
this.iscomparedoc = iscomparedoc;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public String getAdecandtypeflag() {
return adecandtypeflag;
}
public void setAdecandtypeflag(String adecandtypeflag) {
this.adecandtypeflag = adecandtypeflag;
}
public String getRiskgrade() {
return riskgrade;
}
public void setRiskgrade(String riskgrade) {
this.riskgrade = riskgrade;
}
public String getRisksort() {
return risksort;
}
public void setRisksort(String risksort) {
this.risksort = risksort;
}
public String getRiskdescrible() {
return riskdescrible;
}
public void setRiskdescrible(String riskdescrible) {
this.riskdescrible = riskdescrible;
}
public String getEludemeasureadvice() {
return eludemeasureadvice;
}
public void setEludemeasureadvice(String eludemeasureadvice) {
this.eludemeasureadvice = eludemeasureadvice;
}
public String getRecallbill() {
return recallbill;
}
public void setRecallbill(String recallbill) {
this.recallbill = recallbill;
}
}
|
自己的Hibernate批处理 |
自己的hibernate批处理 |
|
package com.tdtech.pdm.create.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.tdtech.pdm.create.dao.DQAssemblyDao;
import com.tdtech.pdm.create.pojo.DQAssemblyPojo;
public class DQAssemblyDaoImpl implements DQAssemblyDao{
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
/**
* 风险评估时的部件更新
*/
public boolean updateRiskEvaluation(List<DQAssemblyPojo> list){
boolean flag=false;
SessionFactory sessionFactory=null;
Session session =null;
Transaction tx=null;
try{
sessionFactory=this.hibernateTemplate.getSessionFactory();
session = sessionFactory.openSession();
tx=session.beginTransaction();
for(DQAssemblyPojo d:list){
String hql="update DQAssemblyPojo d set d.riskgrade=?,d.risksort=?,d.riskdescrible=?,d.eludemeasureadvice=?,d.recallbill=? where d.id=?";
Query query = session.createQuery(hql);
query.setString(0, d.getRiskgrade());
query.setString(1, d.getRisksort());
query.setString(2, d.getRiskdescrible());
query.setString(3, d.getEludemeasureadvice());
query.setString(4, d.getRecallbill());
query.setInteger(5, d.getId());
query.executeUpdate();
}
tx.commit();
flag=true;
}catch(Exception e){
tx.rollback();
}finally{
session.close();
}
return flag;
}
/**
* 更新部件的部件状态和流程状态
*/
public boolean updateStatus(final String assemblystatus,final String status,final int mateId){
boolean flag = false;
int num=0;
try{
num = this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql = "update tb_dqassembly d "+
"set d.assemblystatus=?,d.status=? "+
"where d.nmabid=?";
Query query = session.createSQLQuery(sql);
query.setString(0, assemblystatus);
query.setString(1, status);
query.setInteger(2, mateId);
return query.executeUpdate();
}
});
}catch(Exception e){
e.printStackTrace();
}
if(num>0){
flag=true;
}
return flag;
}
/**
* 保存物料关联部件信息
*/
public boolean saveRelativeInfo(final List<DQAssemblyPojo> list){
boolean flag=false;
int count=0;
try{
count=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int num=0;
for(DQAssemblyPojo d:list){
String hql="update DQAssemblyPojo d set d.adecandtypeflag=?,d.adecribleandtype=?,d.iscomparedoc=?,d.ncdocument=?,d.digest=? where d.dqcode=?";
Query query=session.createQuery(hql);
query.setString(0, d.getAdecandtypeflag());
query.setString(1, d.getAdecribleandtype());
query.setString(2, d.getIscomparedoc());
query.setString(3, d.getNcdocument());
query.setString(4, d.getDigest());
query.setString(5, d.getDqcode());
query.executeUpdate();
num+=1;
}
return num;
}
});
}catch(Exception e){
e.printStackTrace();
}
if(count>0){
flag=true;
}
return flag;
}
/**
* 更新部件信息
*/
public boolean updateDQAssembly(final List<DQAssemblyPojo> list){
boolean flag=false;
int count=0;
try{
count=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int num=0;
for(int i=0;i<list.size();i++){
DQAssemblyPojo n=list.get(i);
String sql="update tb_dqassembly d set d.adviceworkshop=?,d.advicetype=?,d.lapserate=? where d.dqcode=?";
Query query=session.createSQLQuery(sql);
query.setString(0, n.getAdviceworkshop());
query.setString(1, n.getAdvicetype());
query.setString(2, n.getLapserate());
query.setString(3, n.getDqcode());
query.executeUpdate();
num+=1;
}
return num;
}
});
}catch(Exception e){
e.printStackTrace();
}
System.out.println("更新的行数:"+count);
if(count==list.size()){
flag=true;
}
return flag;
}
/**
* 创建鼎桥部件
* @param dQAssemblyPojo
* @return
*/
public boolean addDQAssembly(DQAssemblyPojo dQAssemblyPojo){
boolean flag=false;
try{
this.hibernateTemplate.save(dQAssemblyPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 删除鼎桥部件
* @param id
* @return
*/
public boolean deleteDQAssembly(int id){
boolean flag=false;
try{
DQAssemblyPojo dQAssemblyPojo = this.getHibernateTemplate().get(DQAssemblyPojo.class, id);
this.getHibernateTemplate().delete(dQAssemblyPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 修改鼎桥部件
* @param dQAssemblyPojo
* @return
*/
public boolean updateDQAssembly(DQAssemblyPojo dQAssemblyPojo){
boolean flag=false;
try{
this.getHibernateTemplate().update(dQAssemblyPojo);
flag=true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 修改鼎桥部件
*/
public boolean updateDQAssembly(final Integer id,final Integer newMateAppBillId){
System.out.println("修改鼎桥部件 id="+id+",nmabid="+newMateAppBillId);
boolean flag=false;
try{
int num=0;
num=this.hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String sql="update tb_newMateAppBill set nmabid=? where id=?";
Query query=session.createSQLQuery(sql);
query.setInteger(0, newMateAppBillId);
query.setInteger(1, id);
return query.executeUpdate();
}
});
if(num>0){
flag=true;
}
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 查询所有的鼎桥部件
* @return
*/
public List<DQAssemblyPojo> queryAllDQAssembly(){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
try{
list=this.getHibernateTemplate().find("from DQAssemblyPojo a order by a.id desc");
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 通过id查询鼎桥部件
* @param id
* @return
*/
public DQAssemblyPojo queryDQAssemblyById(int id){
DQAssemblyPojo dQAssemblyPojo=new DQAssemblyPojo();
//System.out.println("通过id查询鼎桥部件: id="+id);
try{
dQAssemblyPojo=(DQAssemblyPojo)this.getHibernateTemplate().find("from DQAssemblyPojo a where a.id="+id).get(0);
}catch(Exception e){
e.printStackTrace();
}
//System.out.println("通过id查询鼎桥部件-"+dQAssemblyPojo.getDqcode());
return dQAssemblyPojo;
}
/**
* 模糊查询
* @param name
* @return
*/
public List<DQAssemblyPojo> queryDQAssemblyByName(final String name){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
try{
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from DQAssemblyPojo a where a.goods like ? order by a.id desc";
Query query=session.createQuery(hql);
query.setString(0, "%"+name+"%");
return query.list();
}
});
}catch(Exception e){
e.printStackTrace();
}
return list;
}
/**
* 生成华为编码
*/
public String generateHwcode(final String code){
//System.out.println("dao------------------"+code);
String hwcode=null;
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
try{
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql="from DQAssemblyPojo a where a.hwcode like ? order by a.hwcode desc";
Query query=session.createQuery(hql);
query.setString(0, code+"%");
return query.list();
}
});
if(list.size()>0){
hwcode=list.get(0).getHwcode();
System.out.println("dao-华为编码为:"+hwcode);
}else{
hwcode=" ";
}
}catch(Exception e){
e.printStackTrace();
hwcode=" ";
}
StringBuffer s=new StringBuffer();
String currentHwcode=null;
int hwcodeInt=0;
if(hwcode!=null && (!(" ".equals(hwcode)))){
s=s.append(hwcode.substring(4));
hwcodeInt=Integer.parseInt(s.toString());
hwcodeInt+=1;
if(hwcodeInt<10){
currentHwcode=hwcode.substring(0,4)+"0000"+hwcodeInt;
}else if(hwcodeInt<100){
currentHwcode=hwcode.substring(0,4)+"000"+hwcodeInt;
}else if(hwcodeInt<1000){
currentHwcode=hwcode.substring(0,4)+"00"+hwcodeInt;
}else if(hwcodeInt<10000){
currentHwcode=hwcode.substring(0,4)+"0"+hwcodeInt;
}else{
currentHwcode=hwcode.substring(0,4)+hwcodeInt;
}
}else{
currentHwcode=code+"00001";
}
System.out.println("dao-生成华为编码-"+currentHwcode);
return currentHwcode;
}
/**
* 通过编码或名称模糊查询
*/
public List<DQAssemblyPojo> queryDQAssembly(final String dqcode,final String outtername){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql=null;
Query query=null;
if((dqcode==null && outtername==null) || ("".equals(dqcode) && "".equals(outtername))){
System.out.println("--------null -----null");
hql="from DQAssemblyPojo d order by d.id asc";
query=session.createQuery(hql);
query.setFirstResult(0);
query.setMaxResults(50);
return query.list();
}
if(dqcode!=null && outtername==null){
hql="from DQAssemblyPojo d where d.dqcode like ? order by d.dqcode asc";
query=session.createQuery(hql);
query.setString(0, "%"+dqcode+"%");
}else if(outtername!=null && dqcode==null){
hql="from DQAssemblyPojo d where d.outtername like ? order by d.dqcode asc";
query=session.createQuery(hql);
query.setString(0, "%"+outtername+"%");
}else if(dqcode!=null && outtername!=null){
hql="from DQAssemblyPojo d where d.dqcode like ? order by d.dqcode asc";
query=session.createQuery(hql);
query.setString(0, "%"+dqcode+"%");
}
return query.list();
}
});
if(list.size()>100){
return null;
}
return list;
}
/**
* 查询多个部件
*/
public List<DQAssemblyPojo> queryMultiAssemblyRecord(final int[] ids){
List<DQAssemblyPojo> list=new ArrayList<DQAssemblyPojo>();
list=this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
int len=ids.length;
String[] s=new String[len];
StringBuffer sb=new StringBuffer("from DQAssemblyPojo d where d.id in(");
for(int i=0;i<len;i++){
if(i==len-1){
sb.append("?");
}else{
sb.append("?"+",");
}
}
sb.append(")");
System.out.println(sb.toString());
Query query = session.createQuery(sb.toString());
for(int i=0;i<ids.length;i++){
query.setInteger(i, ids[i]);
}
return query.list();
}
});
return list;
}
}
|
JS正则表达式验证数字 |
js正则表达式验证数字 |
|
JS正则表达式验证数字
分类: JavaScript 2011-07-21 16:59 514人阅读 评论(0) 收藏 举报
正则表达式functionemail电话
<script type="text/javascript">
function validate(){
var reg = new RegExp("^[0-9]*$");
var obj = document.getElementById("name");
if(!reg.test(obj.value)){
alert("请输入数字!");
}
if(!/^[0-9]*$/.test(obj.value)){
alert("请输入数字!");
}
}
</script>
验证数字的正则表达式集
验证数字:^[0-9]*$
验证n位的数字:^\d{n}$
验证至少n位数字:^\d{n,}$
验证m-n位的数字:^\d{m,n}$
验证零和非零开头的数字:^(0|[1-9][0-9]*)$
验证有两位小数的正实数:^[0-9]+(.[0-9]{2})?$
验证有1-3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$
验证非零的正整数:^\+?[1-9][0-9]*$
验证非零的负整数:^\-[1-9][0-9]*$
验证非负整数(正整数 + 0) ^\d+$
验证非正整数(负整数 + 0) ^((-\d+)|(0+))$
验证长度为3的字符:^.{3}$
验证由26个英文字母组成的字符串:^[A-Za-z]+$
验证由26个大写英文字母组成的字符串:^[A-Z]+$
验证由26个小写英文字母组成的字符串:^[a-z]+$
验证由数字和26个英文字母组成的字符串:^[A-Za-z0-9]+$
验证由数字、26个英文字母或者下划线组成的字符串:^\w+$
验证用户密码:^[a-zA-Z]\w{5,17}$ 正确格式为:以字母开头,长度在6-18之间,只能包含字符、数字和下划线。
验证是否含有 ^%&',;=?$\" 等字符:[^%&',;=?$\x22]+
验证汉字:^[\u4e00-\u9fa5],{0,}$
验证Email地址:^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
验证InternetURL:^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$ ;^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$
验证电话号码:^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$:--正确格式为:XXXX-XXXXXXX,XXXX-XXXXXXXX,XXX-XXXXXXX,XXX-XXXXXXXX,XXXXXXX,XXXXXXXX。
验证身份证号(15位或18位数字):^\d{15}|\d{}18$
验证一年的12个月:^(0?[1-9]|1[0-2])$ 正确格式为:“01”-“09”和“1”“12”
验证一个月的31天:^((0?[1-9])|((1|2)[0-9])|30|31)$ 正确格式为:01、09和1、31。
整数:^-?\d+$
非负浮点数(正浮点数 + 0):^\d+(\.\d+)?$
正浮点数 ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
非正浮点数(负浮点数 + 0) ^((-\d+(\.\d+)?)|(0+(\.0+)?))$
负浮点数 ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
浮点数 ^(-?\d+)(\.\d+)?$
|
部件表与新物料认证表的关联关系 |
部件表与新物料认证表的关联关系 |
|
----------鼎桥部件表(tb_dqassembly)-------------
drop table if exists tb_dqassembly;
create table tb_dqassembly
(
id int unsigned not null auto_increment primary key, //部件编号--主键
hwcode varchar(24), //华为编码--2013-3-18
dqcode varchar(30), //鼎桥编码--2013-3-18
goodsline varchar(50), //产品线
goods varchar(50), //产品
defaultunit varchar(30), //默认单位
resource varchar(30), //来源
template varchar(30), //模板
organise varchar(30), //组织
lifetime varchar(30), //生命周期
/*IBA管理属性*/
sortteanname varchar(50), //分类组名--2013-3-22
smallsortname varchar(50), //小类名称--2013-3-22 14:14
smallSortCode varchar(50), //小类代码
machinetype varchar(50), //机型
parttype varchar(30), //PART类型
bantype varchar(30), //板类型
innertype varchar(50), //对内型号
outtername varchar(50), //对外名称
outterenname varchar(50), //对外英文名称
drawingedition varchar(16), //图纸版本
isenvironment varchar(16), //是否满足环保要求
isnobittern varchar(16), //是否无卤
tackexplain varchar(200) //附加说明
author varchar(30), //创建者--2013-3-22
edition varchar(50), //版本--2013-3-22
status varchar(30), //流程状态--2013-3-22
assemblystatus varchar(30), //部件状态--2013-3-22 14:14
instance varchar(30), //状况--2013-3-22 14:14
createtime varchar(50), //创建时间--2013-3-22 14:14
lastupdatetime varchar(50), //上次修改时间--2013-3-22 14:14
updateperson varchar(30), //修改者--2013-3-22 14:14
sortinfo varchar(50), //分类信息--2013-3-22 14:14
/*规格属性(暂时不添加到数据库)*/
specattribute varchar(100), //规格--2013-3-22 14:14
assemblylength double, //长度--2013-3-22 14:14
assemblyweight double, //净重--2013-3-22 14:14
pintotal int, //PIN总数--2013-3-25 9:24
layercount int, //层数--2013-3-25 9:24
workshoptypeflag varchar(50), //厂家型号标识--2013-3-25 9:24
serialmode varchar(50), //工艺组装方式--2013-3-25 9:24
plyscale varchar(30), //厚径比--2013-3-25 9:24
spellboard varchar(50), //拼版信息--2013-3-25 9:24
isbackboard varchar(16), //是否背板--2013-3-25 9:24
isequipment varchar(16), //是否存在压接器件--2013-3-25 9:24
isflagboard varchar(16), //是否射频板--2013-3-25 9:24
isplumbum varchar(16), //是否无铅--2013-3-25 9:24
ispedance varchar(16), //是否阻抗控制--2013-3-25 9:24
standlevel varchar(30), //适用的刚性印制板检验标准等级--2013-3-25 9:24
especialart varchar(50), //特殊工艺--2013-3-25 9:24
especialask varchar(30), //特殊要求--2013-3-25 9:24
outtypesize varchar(30), //外型尺寸--2013-3-25 9:24
broachaccount int, //钻孔总数--2013-3-25 9:24
minaperture float(12,2), //最小孔径--2013-3-25 9:24
minspace float(12,2), //最小线间距--2013-3-25 9:24
minwidth float(12,2), //最小线宽--2013-3-25 9:24
endecrible varchar(150) //英文描述--2013-3-25 9:24
);
---------------新物料选型认证申请单(tb_newMateAppBill)----------------
drop table if exists tb_newMateAppBill;
create table tb_newMateAppBill
(
id int unsigned not null auto_increment primary key, //主键
applyid varchar(30), //申请单编号
goodsline varchar(50), //产品线
goods varchar(50), //产品
roadsignedition varchar(50), //路标版本
edition varchar(50), //版本
smallSortCode varchar(30), //小类代码
taskname varchar(30), //任务名称
actor varchar(30), //参与者
routerchoose varchar(30), //路由选择
taskvariable varchar(30), //任务变量
begintime varchar(30), //启动时间
endtime varchar(30), //结束时间
lastlimit varchar(30), //最后期限
assemblyid int //鼎桥部件--作为外键
);
--分析部件表tb_dqassembly跟新物料选型认证申请单tb_newMateAppBill的关联关系:
一个申请单可以对应多个部件
这样就构成了一对多的关联关系
1. 新物料选型认证申请单tb_newMateAppBill
package com.tdtech.pdm.create.pojo;
import java.io.Serializable;
/**
* 新物料选型认证POJO--对应数据表tb_newMateAppBill
* @author tWX162737
*
*/
public class NewMateAppBillPojo implements Serializable{
private Integer id; //主键
private String applyid; //申请单编号
private String goodsline; //产品线
private String goods; //产品
private String roadsignedition; //路标版本
private String edition; //版本
private String smallSortCode; //部件的小类代码
public NewMateAppBillPojo(){
}
public NewMateAppBillPojo(Integer id, String applyid, String goodsline,
String goods, String roadsignedition, String edition,
String smallSortCode) {
this.id = id;
this.applyid = applyid;
this.goodsline = goodsline;
this.goods = goods;
this.roadsignedition = roadsignedition;
this.edition = edition;
this.smallSortCode = smallSortCode;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getApplyid() {
return applyid;
}
public void setApplyid(String applyid) {
this.applyid = applyid;
}
public String getGoodsline() {
return goodsline;
}
public void setGoodsline(String goodsline) {
this.goodsline = goodsline;
}
public String getGoods() {
return goods;
}
public void setGoods(String goods) {
this.goods = goods;
}
public String getRoadsignedition() {
return roadsignedition;
}
public void setRoadsignedition(String roadsignedition) {
this.roadsignedition = roadsignedition;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
this.edition = edition;
}
public String getSmallSortCode() {
return smallSortCode;
}
public void setSmallSortCode(String smallSortCode) {
this.smallSortCode = smallSortCode;
}
}
2.部件表tb_dqassembly
package com.tdtech.pdm.create.pojo;
import java.io.Serializable;
/**
* 鼎桥部件Pojo类--对应表tb_dqassembly
* @author tWX162737
*
*/
public class DQAssemblyPojo implements Serializable {
private int id; //主键
private String hwcode; //华为编码
private String dqcode; //鼎桥编码
private String goodsline; //产品线
private String goods; //产品
private String defaultunit; //默认单位
private String resource; //来源
private String template; //模板
private String organise; //组织
private String lifetime; //生命周期
private String smallSortCode;
private String machinetype;
private String parttype;
private String bantype;
private String innertype;
private String outtername;
private String outterenname;
private String drawingedition;
private String isenvironment;
private String isnobittern;
private String tackexplain;
private String sortteanname; //分类组名--2013-3-22
private String smallsortname; //小类名称--2013-3-22 14:14
private String author; //作者--2013-3-22
private String edition ; //版本--2013-3-22
private String status ; //流程状态--2013-3-22
private String assemblystatus ; //部件状态--2013-3-22 14:14
private String instance ; //状况--2013-3-22 14:14
private String createtime ; //创建时间--2013-3-22 14:14
private String lastupdatetime ; //上次修改时间--2013-3-22 14:14
private String updateperson ; //修改者--2013-3-22 14:14
private String sortinfo ; //分类信息--2013-3-22 14:14
private Integer pintotal; //PIN总数--2013-3-25 9:24
private Integer layercount; //层数--2013-3-25 9:24
private String workshoptypeflag ; //厂家型号标识--2013-3-25 9:24
private String serialmode ; //工艺组装方式--2013-3-25 9:24
private String plyscale ; //厚径比--2013-3-25 9:24
private String spellboard ; //拼版信息--2013-3-25 9:24
private String isbackboard ; //是否背板--2013-3-25 9:24
private String isequipment; //是否存在压接器件--2013-3-25 9:24
private String isflagboard; //是否射频板--2013-3-25 9:24
private String isplumbum; //是否无铅--2013-3-25 9:24
private String ispedance; //是否阻抗控制--2013-3-25 9:24
private String standlevel; //适用的刚性印制板检验标准等级--2013-3-25 9:24
private String especialart; //特殊工艺--2013-3-25 9:24
private String especialask; //特殊要求--2013-3-25 9:24
private String outtypesize; //外型尺寸--2013-3-25 9:24
private Integer broachaccount; //钻孔总数--2013-3-25 9:24
private Float minaperture; //最小孔径--2013-3-25 9:24
private Float minspace; //最小线间距--2013-3-25 9:24
private Float minwidth; //最小线宽--2013-3-25 9:24
private String endecrible; //英文描述--2013-3-25 9:24
/**
* 无参构造方法
*/
public DQAssemblyPojo(){
}
/**
* 全参构造方法
* @param id
* @param goodsline
* @param goods
* @param defaultunit
* @param resource
* @param template
* @param organise
* @param lifetime
*/
public DQAssemblyPojo(int id, String hwcode, String dqcode,
String goodsline, String goods, String defaultunit,
String resource, String template, String organise, String lifetime,
String smallSortCode, String machinetype, String parttype,
String bantype, String innertype, String outtername,
String outterenname, String drawingedition, String isenvironment,
String isnobittern, String tackexplain, String sortteanname,
String smallsortname, String author, String edition, String status,
String assemblystatus, String instance, String createtime,
String lastupdatetime, String updateperson, String sortinfo,
Integer pintotal, Integer layercount, String workshoptypeflag,
String serialmode, String plyscale, String spellboard,
String isbackboard, String isequipment, String isflagboard,
String isplumbum, String ispedance, String standlevel,
String especialart, String especialask, String outtypesize,
Integer broachaccount, Float minaperture, Float minspace,
Float minwidth, String endecrible) {
this.id = id;
this.hwcode = hwcode;
this.dqcode = dqcode;
this.goodsline = goodsline;
this.goods = goods;
this.defaultunit = defaultunit;
this.resource = resource;
this.template = template;
this.organise = organise;
this.lifetime = lifetime;
this.smallSortCode = smallSortCode;
this.machinetype = machinetype;
this.parttype = parttype;
this.bantype = bantype;
this.innertype = innertype;
this.outtername = outtername;
this.outterenname = outterenname;
this.drawingedition = drawingedition;
this.isenvironment = isenvironment;
this.isnobittern = isnobittern;
this.tackexplain = tackexplain;
this.sortteanname = sortteanname;
this.smallsortname = smallsortname;
this.author = author;
this.edition = edition;
this.status = status;
this.assemblystatus = assemblystatus;
this.instance = instance;
this.createtime = createtime;
this.lastupdatetime = lastupdatetime;
this.updateperson = updateperson;
this.sortinfo = sortinfo;
this.pintotal = pintotal;
this.layercount = layercount;
this.workshoptypeflag = workshoptypeflag;
this.serialmode = serialmode;
this.plyscale = plyscale;
this.spellboard = spellboard;
this.isbackboard = isbackboard;
this.isequipment = isequipment;
this.isflagboard = isflagboard;
this.isplumbum = isplumbum;
this.ispedance = ispedance;
this.standlevel = standlevel;
this.especialart = especialart;
this.especialask = especialask;
this.outtypesize = outtypesize;
this.broachaccount = broachaccount;
this.minaperture = minaperture;
this.minspace = minspace;
this.minwidth = minwidth;
this.endecrible = endecrible;
}
/**
* setter与getter方法
* @return
*/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsline() {
return goodsline;
}
public String getHwcode() {
return hwcode;
}
public void setHwcode(String hwcode) {
this.hwcode = hwcode;
}
public String getDqcode() {
return dqcode;
}
public void setDqcode(String dqcode) {
this.dqcode = dqcode;
}
public void setGoodsline(String goodsline) {
this.goodsline = goodsline;
}
public String getGoods() {
return goods;
}
public void setGoods(String goods) {
this.goods = goods;
}
public String getDefaultunit() {
return defaultunit;
}
public void setDefaultunit(String defaultunit) {
this.defaultunit = defaultunit;
}
public String getResource() {
return resource;
}
public void setResource(String resource) {
this.resource = resource;
}
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
public String getOrganise() {
return organise;
}
public void setOrganise(String organise) {
this.organise = organise;
}
public String getLifetime() {
return lifetime;
}
public void setLifetime(String lifetime) {
this.lifetime = lifetime;
}
public String getSmallSortCode() {
return smallSortCode;
}
public void setSmallSortCode(String smallSortCode) {
this.smallSortCode = smallSortCode;
}
public String getMachinetype() {
return machinetype;
}
public void setMachinetype(String machinetype) {
this.machinetype = machinetype;
}
public String getParttype() {
return parttype;
}
public void setParttype(String parttype) {
this.parttype = parttype;
}
public String getBantype() {
return bantype;
}
public void setBantype(String bantype) {
this.bantype = bantype;
}
public String getInnertype() {
return innertype;
}
public void setInnertype(String innertype) {
this.innertype = innertype;
}
public String getOuttername() {
return outtername;
}
public void setOuttername(String outtername) {
this.outtername = outtername;
}
public String getOutterenname() {
return outterenname;
}
public void setOutterenname(String outterenname) {
this.outterenname = outterenname;
}
public String getDrawingedition() {
return drawingedition;
}
public void setDrawingedition(String drawingedition) {
this.drawingedition = drawingedition;
}
public String getIsenvironment() {
return isenvironment;
}
public void setIsenvironment(String isenvironment) {
this.isenvironment = isenvironment;
}
public String getIsnobittern() {
return isnobittern;
}
public void setIsnobittern(String isnobittern) {
this.isnobittern = isnobittern;
}
public String getTackexplain() {
return tackexplain;
}
public void setTackexplain(String tackexplain) {
this.tackexplain = tackexplain;
}
public String getSortteanname() {
return sortteanname;
}
public void setSortteanname(String sortteanname) {
this.sortteanname = sortteanname;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
this.edition = edition;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getAssemblystatus() {
return assemblystatus;
}
public void setAssemblystatus(String assemblystatus) {
this.assemblystatus = assemblystatus;
}
public String getInstance() {
return instance;
}
public void setInstance(String instance) {
this.instance = instance;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public String getLastupdatetime() {
return lastupdatetime;
}
public void setLastupdatetime(String lastupdatetime) {
this.lastupdatetime = lastupdatetime;
}
public String getUpdateperson() {
return updateperson;
}
public void setUpdateperson(String updateperson) {
this.updateperson = updateperson;
}
public String getSortinfo() {
return sortinfo;
}
public void setSortinfo(String sortinfo) {
this.sortinfo = sortinfo;
}
public String getSmallsortname() {
return smallsortname;
}
public void setSmallsortname(String smallsortname) {
this.smallsortname = smallsortname;
}
public String getWorkshoptypeflag() {
return workshoptypeflag;
}
public void setWorkshoptypeflag(String workshoptypeflag) {
this.workshoptypeflag = workshoptypeflag;
}
public String getSerialmode() {
return serialmode;
}
public void setSerialmode(String serialmode) {
this.serialmode = serialmode;
}
public String getPlyscale() {
return plyscale;
}
public void setPlyscale(String plyscale) {
this.plyscale = plyscale;
}
public String getSpellboard() {
return spellboard;
}
public void setSpellboard(String spellboard) {
this.spellboard = spellboard;
}
public String getIsbackboard() {
return isbackboard;
}
public void setIsbackboard(String isbackboard) {
this.isbackboard = isbackboard;
}
public String getIsequipment() {
return isequipment;
}
public void setIsequipment(String isequipment) {
this.isequipment = isequipment;
}
public String getIsflagboard() {
return isflagboard;
}
public void setIsflagboard(String isflagboard) {
this.isflagboard = isflagboard;
}
public String getIsplumbum() {
return isplumbum;
}
public void setIsplumbum(String isplumbum) {
this.isplumbum = isplumbum;
}
public String getIspedance() {
return ispedance;
}
public void setIspedance(String ispedance) {
this.ispedance = ispedance;
}
public String getStandlevel() {
return standlevel;
}
public void setStandlevel(String standlevel) {
this.standlevel = standlevel;
}
public String getEspecialart() {
return especialart;
}
public void setEspecialart(String especialart) {
this.especialart = especialart;
}
public String getEspecialask() {
return especialask;
}
public void setEspecialask(String especialask) {
this.especialask = especialask;
}
public String getOuttypesize() {
return outtypesize;
}
public void setOuttypesize(String outtypesize) {
this.outtypesize = outtypesize;
}
public String getEndecrible() {
return endecrible;
}
public void setEndecrible(String endecrible) {
this.endecrible = endecrible;
}
public Integer getPintotal() {
return pintotal;
}
public void setPintotal(Integer pintotal) {
this.pintotal = pintotal;
}
public Integer getLayercount() {
return layercount;
}
public void setLayercount(Integer layercount) {
this.layercount = layercount;
}
public Integer getBroachaccount() {
return broachaccount;
}
public void setBroachaccount(Integer broachaccount) {
this.broachaccount = broachaccount;
}
public Float getMinaperture() {
return minaperture;
}
public void setMinaperture(Float minaperture) {
this.minaperture = minaperture;
}
public Float getMinspace() {
return minspace;
}
public void setMinspace(Float minspace) {
this.minspace = minspace;
}
public Float getMinwidth() {
return minwidth;
}
public void setMinwidth(Float minwidth) {
this.minwidth = minwidth;
}
}
3. NewMateAppBillPojo.hbm.xml
4. DQAssemblyPojo.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.tdtech.pdm.create.pojo">
<class name="DQAssemblyPojo" table="tb_dqassembly">
<id name="id">
<generator class="native"></generator>
</id>
<property name="hwcode"></property>
<property name="dqcode"></property>
<!-- 常规信息 -->
<property name="goodsline"></property>
<property name="goods"></property>
<property name="defaultunit"></property>
<property name="resource"></property>
<property name="template"></property>
<property name="organise"></property>
<property name="lifetime"></property>
<!-- IBA管理属性 -->
<property name="smallSortCode"></property>
<property name="machinetype"></property>
<property name="parttype"></property>
<property name="bantype"></property>
<property name="innertype"></property>
<property name="outtername"></property>
<property name="outterenname"></property>
<property name="drawingedition"></property>
<property name="isenvironment"></property>
<property name="isnobittern"></property>
<property name="tackexplain"></property>
<!-- 2013-3-22 -->
<property name="sortteanname"></property>
<property name="smallsortname"></property>
<property name="author"></property>
<property name="edition"></property>
<property name="status"></property>
<property name="assemblystatus"></property>
<property name="instance"></property>
<property name="createtime"></property>
<property name="lastupdatetime"></property>
<property name="updateperson"></property>
<property name="sortinfo"></property>
<!-- 2013-3-25 -->
<property name="pintotal"></property>
<property name="layercount"></property>
<property name="workshoptypeflag"></property>
<property name="serialmode"></property>
<property name="plyscale"></property>
<property name="spellboard"></property>
<property name="isbackboard"></property>
<property name="isequipment"></property>
<property name="isflagboard"></property>
<property name="isplumbum"></property>
<property name="ispedance"></property>
<property name="standlevel"></property>
<property name="especialart"></property>
<property name="especialask"></property>
<property name="outtypesize"></property>
<property name="broachaccount"></property>
<property name="minaperture"></property>
<property name="minspace"></property>
<property name="minwidth"></property>
<property name="endecrible"></property>
</class>
</hibernate-mapping>
|
Struts2文件下载12 |
struts2文件下载 12 |
|
Struts2文件下载
strutsweb
一个简单的利用struts2做文件下载的demo……
首先配好struts:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml——这里是重点
<package name="file" namespace="/file" extends="struts-default">
<action name="fileAction" class="com.struts2.file.FileAction">
<!-- 下载文件配置 -->
<!--type 为 stream 应用 StreamResult 处理-->
<result name="down" type="stream">
<!-- 不管实际类型,待下载文件 ContentType 统一指定为 application/octet-stream 默认为 text/plain -->
<param name="contentType">application/octet-stream</param>
<!-- 默认就是 inputStream,它将会指示 StreamResult 通过 inputName 属性值的 getter 方法,比如这里就是 getInputStream() 来获取下载文件的内容,意味着你的 Action 要有这个方法 -->
<param name="inputName">inputStream</param>
<!-- 默认为 inline(在线打开),设置为 attachment 将会告诉浏览器下载该文件,filename 指定下载文件保存时的文件名,若未指定将会是以浏览的页面名作为文件名,如以 download.action 作为文件名,这里使用的是动态文件名,${fileName}, 它将通过 Action 的 getFileName() 获得文件名-->
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<!-- 输出时缓冲区的大小 -->
<param name="bufferSize">4096</param>
</result>
</action>
</package>
当result为stream类型时,struts2会自动根据你配置好的参数下载文件。
其中主要使用的参数是:
contentType 指定下载文件的文件类型 —— application/octet-stream 表示无限制
inputName 流对象名 —— 比如这里写inputStream,它就会自动去找Action中的getInputStream方法。
contentDisposition 使用经过转码的文件名作为下载文件名 —— 默认格式是attachment;filename="${fileName}",将调用该Action中的getFileName方法。
bufferSize 下载文件的缓冲大小
//Action调用的下载文件方法
public String down() {
return "down";
}
//获得下载文件的内容,可以直接读入一个物理文件或从数据库中获取内容
public InputStream getInputStream() throws Exception {
String dir = servletContext.getRealPath("/file/upload");
File file = new File(dir, "icon.png");
if (file.exists()) {
//下载文件
return new FileInputStream(file);
//和 Servlet 中不一样,这里我们不需对输出的中文转码为 ISO8859-1
//将内容(Struts2 文件下载测试)直接写入文件,下载的文件名必须是文本(txt)类型
//return new ByteArrayInputStream("Struts2 文件下载测试".getBytes());
}
return null;
}
// 对于配置中的 ${fileName}, 获得下载保存时的文件名
public String getFileName() {
String fileName ="图标.png";
try {
// 中文文件名也是需要转码为 ISO8859-1,否则乱码
return new String(fileName.getBytes(), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
return "icon.png";
}
}
* 注意使用getResourceAsStream方法时,文件路径必须是以“/”开头,且是相对路径。这个路径是相对于项目根目录的。
* 可以用return new FileInputStream(fileName)的方法来得到绝对路径的文件。
在WEB-INF下随意丢一个test.txt,部署好后进入浏览器,输入tomcat地址/项目路径/download.action?fileName=test.txt即可下载到该文件。
附:contentType类型.
'ez' => 'application/andrew-inset',
'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'doc' => 'application/msword',
'bin' => 'application/octet-stream',
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'class' => 'application/octet-stream',
'so' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'wbxml' => 'application/vnd.wap.wbxml',
'wmlc' => 'application/vnd.wap.wmlc',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'bcpio' => 'application/x-bcpio',
'vcd' => 'application/x-cdlink',
'pgn' => 'application/x-chess-pgn',
'cpio' => 'application/x-cpio',
'csh' => 'application/x-csh',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'spl' => 'application/x-futuresplash',
'gtar' => 'application/x-gtar',
'hdf' => 'application/x-hdf',
'js' => 'application/x-javas
cript',
'skp' => 'application/x-koan',
'skd' => 'application/x-koan',
'skt' => 'application/x-koan',
'skm' => 'application/x-koan',
'latex' => 'application/x-latex',
'nc' => 'application/x-netcdf',
'cdf' => 'application/x-netcdf',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'tex' => 'application/x-tex',
'texinfo' => 'application/x-texinfo',
'texi' => 'application/x-texinfo',
't' => 'application/x-troff',
'tr' => 'application/x-troff',
'roff' => 'application/x-troff',
'man' => 'application/x-troff-man',
'me' => 'application/x-troff-me',
'ms' => 'application/x-troff-ms',
'ustar' => 'application/x-ustar',
'src' => 'application/x-wais-source',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => 'application/zip',
'au' => 'audio/basic',
'snd' => 'audio/basic',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'kar' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'm3u' => 'audio/x-mpegurl',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'wav' => 'audio/x-wav',
'pdb' => 'chemical/x-pdb',
'xyz' => 'chemical/x-xyz',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'ief' => 'image/ief',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'djvu' => 'image/vnd.djvu',
'djv' => 'image/vnd.djvu',
'wbmp' => 'image/vnd.wap.wbmp',
'ras' => 'image/x-cmu-raster',
'pnm' => 'image/x-portable-anymap',
'pbm' => 'image/x-portable-bitmap',
'pgm' => 'image/x-portable-graymap',
'ppm' => 'image/x-portable-pixmap',
'rgb' => 'image/x-rgb',
'xbm' => 'image/x-xbitmap',
'xpm' => 'image/x-xpixmap',
'xwd' => 'image/x-xwindowdump',
'igs' => 'model/iges',
'iges' => 'model/iges',
'msh' => 'model/mesh',
'mesh' => 'model/mesh',
'silo' => 'model/mesh',
'wrl' => 'model/vrml',
'vrml' => 'model/vrml',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'asc' => 'text/plain',
'txt' => 'text/plain',
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'sgml' => 'text/sgml',
'sgm' => 'text/sgml',
'tsv' => 'text/tab-separated-values',
'wml' => 'text/vnd.wap.wml',
'wmls' => 'text/vnd.wap.wmlscript',
'etx' => 'text/x-setext',
'xsl' => 'text/xml',
'xml' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'mxu' => 'video/vnd.mpegurl',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
'ice' => 'x-conference/x-cooltalk'
|
网页上的表格边框设计更多效果变化 |
网页上的表格边框设计更多效果变化 |
|
网页上的表格边框设计更多效果变化
CSSDreamweaver
设置表格边框方法一,编写CSS代码定义样式表:
首先,要了解这些常用边框类型说明:
none: 指定表格没有边框,所以边框宽度为0。
dotted: 由点线组成的表格边框。
dashed: 由虚线组成的表格边框。
solid: 由实线组成的表格边框。
double: 由双实线组成的表格边框。
groove: 槽线效果边框。
ridge: 脊线效果边框,和槽线效果相反。
inset: 内凹效果边框。
outset: 外凸效果边框,和内凹效果相反。
以下CSS代码使用时,均应放置在这样的样式表style标签中,这些style标签通常放置在网页文件的前部:
<style>
样式名称1 { 样式代码1 }
样式名称2 { 样式代码2 }
样式名称3 { 样式代码3 }
......
</style>
应用这些样式代码时,应把样式名称添加到表格中,类似这样:
<table width=300 class=样式名称1>
这是未使用CSS代码定义,直接指定表格边框宽度和颜色的做法,也是很多初学者最初使用方法,可行,但效果不够完美。如图1,灰色虚线边框。通过Dreamweaver的设计界面直接设置表格边框宽度就是这样的。
<table width=300 border=1 cellpadding=0 cellspacing=0 bordercolor=#CCCCCC>
<tr>
<td>文字第一行</td>
</tr>
<tr>
<td>文字第二行</td>
</tr>
</table>
[图1]
http://image1.club.sohu.com/pic/4a/51/hxzyeebec742a86e7d0c.jpg
这个style标签,定义了图2这样的表格,边框宽度为1像素,灰色虚线边框,只显示表格的最外层边线,里面的线不显示
<style>
.Table1 { border: 1px dashed #CCCCCC; }
</style>
应用到表格中时,这样写:
<table width=300 class=Table1>
<tr>
<td>文字第一行</td>
</tr>
<tr>
<td>文字第二行</td>
</tr>
</table>
[图2]
http://image1.club.sohu.com/pic/2d/81/hxzy39a8f11b6d7deff3.jpg
这个style标签,定义了图3这样的表格,边框宽度为1像素,灰色实线边框,表格内外层边线都显示
<style>
.Table1 { border-collapse:collapse; }
.Table1 td { border: 1px solid #CCCCCC; }
</style>
应用到表格中时,这样写:
<table width=300 class=Table1>
<tr>
<td>文字第一行</td>
</tr>
<tr>
<td>文字第二行</td>
</tr>
</table>
[图3]
http://image1.club.sohu.com/pic/c5/e2/hxzya1993abd30c55948.jpg
这个style标签,定义了图4这样的表格,边框宽度为1像素,灰色虚线边框,表格内外层边线都显示
<style>
.Table1 { border-collapse:collapse; }
.Table1 td { border: 1px dashed #CCCCCC; }
</style>
应用到表格中时,这样写:
<table width=300 class=Table1>
<tr>
<td>文字第一行1列</td>
<td>文字第一行2列</td>
</tr>
<tr>
<td>文字第二行1列</td>
<td>文字第二行2列</td>
</tr>
</table>
[图4]
http://image1.club.sohu.com/pic/34/af/hxzyabc690a69263a702.jpg
<B>设置表格边框方法二,不使用CSS代码定义style标签,用表格的rules属性和frame属性改变边框样式</B>
首先,要了解frame属性可取的参数及含义:
void - 默认值。表示不显示表格最外围的边框。
box - 同时显示四条边框。
border - 同时显示四条边框。
above - 只显示顶部边框。
below - 只显示底部边框。
lhs - 只显示左侧边框。
rhs - 只显示右侧边框。
hsides - 只显示水平方向的两条边框。
vsides - 只显示垂直方面的两条边框。
并且,要了解rules属性可取的参数及含义:
none - 默认值。无边框。
groups - 为行组或列组加边框。
rows - 为行加边框。
cols - 为列加边框。
all - 为所有行列(单元格)加边框
如图5,隐藏表格中间的横线:
<table width=300 border=1 bordercolor=#CCCCCC style=border-collapse:collapse; rules=cols>
<tr>
<td>文字第一行1列</td>
<td>文字第一行2列</td>
</tr>
<tr>
<td>文字第二行1列</td>
<td>文字第二行2列</td>
</tr>
</table>
[图5]
http://image1.club.sohu.com/pic/a8/b3/hxzyca2646065c7055d4.jpg
如图6,隐藏表格的外框:
<table width=300 border=1 bordercolor=#CCCCCC style=border-collapse:collapse; frame=void>
<tr>
<td>文字第一行1列</td>
<td>文字第一行2列</td>
</tr>
<tr>
<td>文字第二行1列</td>
<td>文字第二行2列</td>
</tr>
</table>
[图6]
http://image1.club.sohu.com/pic/e0/3c/hxzyac36033d8faec200.jpg
如图7,隐藏表格的竖线,只显示横线,造成稿纸的效果:
<table width=300 border=1 bordercolor=#CCCCCC style=border-collapse:collapse; frame=hsides rules=rows>
<tr>
<td>文字第一行1列</td>
<td>文字第一行2列</td>
</tr>
<tr>
<td>文字第二行1列</td>
<td>文字第二行2列</td>
</tr>
</table>
|