`
yshlin
  • 浏览: 61304 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

许多段代码

    博客分类:
  • java
阅读更多

 

1、项目地址与类的包名路径

String pro = System.getProperty("user.dir");
String pkg = CgSpringMvcIbatis.class.getPackage().getName().replaceAll("\\.","\\\\"); 

 

2、根据模板生成文件(用时需修改)

Template tJsp = cfg.getTemplate("js.ftl");// 模板名称
tJsp.setEncoding("UTF-8");
String jspDir = jMap.get("conpath").toString();
File fileDir = new File(jspDir);
org.apache.commons.io.FileUtils.forceMkdir(fileDir);
File output_service = new File(jspDir + "/default.js");
Writer writer_service = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output_service), "UTF-8"));
tJsp.process(jMap, writer_service);
writer_service.close();

 

3、泛型接口Ibatis

/**
 * Ibatis Dao 接口
 * 通用增删改查\带分页\单条
 * @author mywhile
 * @param <T>
 */
public abstract interface IbatisDao<T> {
	public void delete(String guid, String sqlMapId);
	public void save(T bean, String sqlMapId);
	public void update(T bean, String sqlMapId);
	public List<T> query(String sqlMapId);
	public T queryRowByGuid(String guid, String sqlMapId);
	public List<T> queryPageData(String sqlMapId, Map map, int pageNo, int pageSize);	
	public int queryCountRow(Map map, String SqlMapId);
}

 

4、泛型接口实现Ibatis

import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import sdcncsi.ibatis.test.dao.IbatisDao;

@SuppressWarnings("unchecked")
public class IbatisServicesImpl<T>
		extends SqlMapClientDaoSupport implements IbatisDao<T> {
	@Override
	public void delete(String guid, String sqlMapId) {
		getSqlMapClientTemplate().delete(sqlMapId, guid);
	}
	@Override
	public List<T> query(String sqlMapId) {
		return getSqlMapClientTemplate().queryForList(sqlMapId);
	}
	@Override
	public T queryRowByGuid(String guid, String sqlMapId) {
		return (T) getSqlMapClientTemplate().queryForObject(sqlMapId, guid);
	}
	@Override
	public void save(T bean, String sqlMapId) {
		getSqlMapClientTemplate().insert(sqlMapId, bean);
	}
	@Override
	public void update(T bean, String sqlMapId) {
		getSqlMapClientTemplate().update(sqlMapId, bean);
	}
	@Override
	public List<T> queryPageData(String sqlMapId, Map map, int pageNo, int pageSize) {
		map.put("pageNo", pageNo == 1 ? 0 : pageSize);
		map.put("pageSize", pageSize);
		return getSqlMapClientTemplate().queryForList(sqlMapId, map);//, pageNo, pageSize
	}
	@Override
	public int queryCountRow(Map map, String sqlMapId) {
		return (Integer) getSqlMapClientTemplate().queryForObject(sqlMapId, map);
	}
}

 

5、Ibatis中取SQL

String sql = null;
SqlMapClientImpl sqlmap = (SqlMapClientImpl)this.getSqlMapClient();   
MappedStatement stmt = sqlmap.getMappedStatement(sqlMapId);   
Sql stmtSql = stmt.getSql();   
SessionScope session = new SessionScope();
StatementScope scope = new StatementScope(session);
scope.setStatement(stmt);   
sql = stmtSql.getSql(scope, map);

 6、附件=Spring+Ibatis代码生成器;

7、文件读取

/**
	 * 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
	 * @param fileName 文件的名
	 */
	public static void readFileByBytes(String fileName) {
		File file = new File(fileName);
		InputStream in = null;
		try {
			System.out.println("以字节为单位读取文件内容,一次读一个字节:");
			// 一次读一个字节
			in = new FileInputStream(file);
			int tempbyte;
			while ((tempbyte = in.read()) != -1) {
				System.out.write(tempbyte);
			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		try {
			System.out.println("以字节为单位读取文件内容,一次读多个字节:");
			// 一次读多个字节
			byte[] tempbytes = new byte[100];
			int byteread = 0;
			in = new FileInputStream(fileName);
			FileReadWrite.showAvailableBytes(in);
			// 读入多个字节到字节数组中,byteread为一次读入的字节数
			while ((byteread = in.read(tempbytes)) != -1) {
				System.out.write(tempbytes, 0, byteread);
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e1) {
				}
			}
		}
	}
	/**
	 * 以字符为单位读取文件,常用于读文本,数字等类型的文件
	 * @param fileName 	文件名
	 */
	public static void readFileByChars(String fileName) {
		File file = new File(fileName);
		Reader reader = null;
		try {
			System.out.println("以字符为单位读取文件内容,一次读一个字节:");
			// 一次读一个字符
			reader = new InputStreamReader(new FileInputStream(file));
			int tempchar;
			while ((tempchar = reader.read()) != -1) {
				// 对于windows下,rn这两个字符在一起时,表示一个换行。
				// 但如果这两个字符分开显示时,会换两次行。
				// 因此,屏蔽掉r,或者屏蔽n。否则,将会多出很多空行。
				if (((char) tempchar) != 'r') {
					System.out.print((char) tempchar);
				}
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			System.out.println("以字符为单位读取文件内容,一次读多个字节:");
			// 一次读多个字符
			char[] tempchars = new char[30];
			int charread = 0;
			reader = new InputStreamReader(new FileInputStream(fileName));
			// 读入多个字符到字符数组中,charread为一次读取字符数
			while ((charread = reader.read(tempchars)) != -1) {
				// 同样屏蔽掉r不显示
				if ((charread == tempchars.length)
						&& (tempchars[tempchars.length - 1] != 'r')) {
					System.out.print(tempchars);
				} else {
					for (int i = 0; i < charread; i++) {
						if (tempchars[i] == 'r') {
							continue;
						} else {
							System.out.print(tempchars[i]);
						}
					}
				}
			}
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
	}

	/**
	 * 以行为单位读取文件,常用于读面向行的格式化文件
	 * @param fileName 	文件名
	 */
	public static void readFileByLines(String fileName) {
		File file = new File(fileName);
		BufferedReader reader = null;
		try {
			System.out.println("以行为单位读取文件内容,一次读一整行:");
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			// 一次读入一行,直到读入null为文件结束
			while ((tempString = reader.readLine()) != null) {
				// 显示行号
				System.out.println("line " + line + ": " + tempString);
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
	}
	/**
	 * 随机读取文件内容
	 * @param fileName 	文件名
	 */
	public static void readFileByRandomAccess(String fileName) {
		RandomAccessFile randomFile = null;
		try {
			System.out.println("随机读取一段文件内容:");
			// 打开一个随机访问文件流,按只读方式
			randomFile = new RandomAccessFile(fileName, "r");
			// 文件长度,字节数
			long fileLength = randomFile.length();
			// 读文件的起始位置
			int beginIndex = (fileLength > 4) ? 4 : 0;
			// 将读文件的开始位置移到beginIndex位置。
			randomFile.seek(beginIndex);
			byte[] bytes = new byte[10];
			int byteread = 0;
			// 一次读10个字节,如果文件内容不足10个字节,则读剩下的字节。
			// 将一次读取的字节数赋给byteread
			while ((byteread = randomFile.read(bytes)) != -1) {
				System.out.write(bytes, 0, byteread);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (randomFile != null) {
				try {
					randomFile.close();
				} catch (IOException e1) {
				}
			}
		}
	}
	/**
	 * 显示输入流中还剩的字节数
	 * @param in
	 */
	private static void showAvailableBytes(InputStream in) {
		try {
			System.out.println("当前字节输入流中的字节数为:" + in.available());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 将内容追加到文件尾部
	 * A方法追加文件:使用RandomAccessFile
	 * @param fileName	文件名
	 * @param content 	追加的内容
	 */
	public static void appendMethodA(String fileName, String content) {
		try {
			// 打开一个随机访问文件流,按读写方式
			RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
			// 文件长度,字节数
			long fileLength = randomFile.length();
			// 将写文件指针移到文件尾。
			randomFile.seek(fileLength);
			randomFile.writeBytes(content);
			randomFile.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 将内容追加到文件尾部
	 * B方法追加文件:使用FileWriter
	 * @param fileName
	 * @param content
	 */
	public static void appendMethodB(String fileName, String content) {
		try {
			// 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
			FileWriter writer = new FileWriter(fileName, true);
			writer.write(content);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

 

8、Myeclipse生成序列号
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MyEclipseGEN {
	private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.";

	public String getSerial(String userId, String licenseNum) {
		java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.add(1, 3);
		cal.add(6, -1);
		java.text.NumberFormat nf = new java.text.DecimalFormat("000");
		licenseNum = nf.format(Integer.valueOf(licenseNum));
		String verTime = new StringBuilder("-").append(new java.text.SimpleDateFormat("yyMMdd").format(cal.getTime())).append("0").toString();
		String type = "YE3MP-";
		String need = new StringBuilder(userId.substring(0, 1)).append(type).append("300").append(licenseNum).append(verTime).toString();
		String dx = new StringBuilder(need).append(LL).append(userId).toString();
		int suf = this.decode(dx);
		String code = new StringBuilder(need).append(String.valueOf(suf)).toString();
		return this.change(code);
	}

	private int decode(String s) {
		int i;
		char[] ac;
		int j;
		int k;
		i = 0;
		ac = s.toCharArray();
		j = 0;
		k = ac.length;
		while (j < k) {
			i = (31 * i) + ac[j];
			j++;
		}
		return Math.abs(i);
	}

	private String change(String s) {
		byte[] abyte0;
		char[] ac;
		int i;
		int k;
		int j;
		abyte0 = s.getBytes();
		ac = new char[s.length()];
		i = 0;
		k = abyte0.length;
		while (i < k) {
			j = abyte0[i];
			if ((j >= 48) && (j <= 57)) {
				j = (((j - 48) + 5) % 10) + 48;
			} else if ((j >= 65) && (j <= 90)) {
				j = (((j - 65) + 13) % 26) + 65;
			} else if ((j >= 97) && (j <= 122)) {
				j = (((j - 97) + 13) % 26) + 97;
			}
			ac[i] = (char) j;
			i++;
		}
		return String.valueOf(ac);
	}

	public MyEclipseGEN() {
		super();
	}

	public static void main(String[] args) {
		try {
			System.out.println("please input register name:");
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String userId = null;
			userId = reader.readLine();
			MyEclipseGEN myeclipsegen = new MyEclipseGEN();
			String res = myeclipsegen.getSerial(userId, "20");
			System.out.println("Serial:" + res);
			reader.readLine();
		} catch (IOException ex) {
		}
	}
}
 
9、Myeclipse7.1插件添加
public class Plugin {
	private String path;

	public Plugin(String path) {
		this.path = path;
	}

	public void print() {
		List list = getFileList(path);
		if (list == null) {
			return;
		}
		int length = list.size();
		for (int i = 0; i < length; i++) {
			String result = "";
			String thePath = getFormatPath(getString(list.get(i)));
			File file = new File(thePath);
			if (file.isDirectory()) {
				String fileName = file.getName();
				if (fileName.indexOf("_") < 0) {
					continue;
				}
				String[] filenames = fileName.split("_");
				String filename1 = filenames[0];
				String filename2 = filenames[1];
				result = filename1 + "," + filename2 + ",file:/" + path + "\\"
						+ fileName + "\\,4,false";
				System.out.println(result);
			} else if (file.isFile()) {
				String fileName = file.getName();
				if (fileName.indexOf("_") < 0) {
					continue;
				}
				String[] filenames = fileName.split("_");
				String filename1 = filenames[0];
				String filename2 = filenames[1].substring(0, filenames[1]
						.lastIndexOf("."));
				result = filename1 + "," + filename2 + ",file:/" + path + "\\"
						+ fileName + ",4,false";
				System.out.println(result);
			}
		}
	}

	public List getFileList(String path) {
		path = getFormatPath(path);
		path = path + "/";
		File filePath = new File(path);
		if (!filePath.isDirectory()) {
			return null;
		}
		String[] filelist = filePath.list();
		List filelistFilter = new ArrayList();
		for (int i = 0; i < filelist.length; i++) {
			String tempfilename = getFormatPath(path + filelist[i]);
			filelistFilter.add(tempfilename);
		}
		return filelistFilter;
	}

	public String getString(Object object) {
		if (object == null) {
			return "";
		}
		return String.valueOf(object);
	}

	public String getFormatPath(String path) {
		path = path.replaceAll("\\\\", "/");
		path = path.replaceAll("//", "/");
		return path;
	}

	public static void main(String[] args) {
		new Plugin("D:\\Program Files\\MyEclipse 7.1\\plugins").print();
	}
}
 
 
分享到:
评论

相关推荐

    最强弹窗广告代码,超级弹窗代码,超强弹窗代码,强制弹窗代码系统(好铭堂)

    “好铭堂超级弹窗广告系统”是一个可以用一行链接或一小段音视频播放代码调用,就能随意在各种博客首页、博文中、论坛贴子中、电子邮件中弹出广告、视频、网页,而不被浏览器和一些软件拦截 。不用你安装使用什么...

    用html写爱心2种方法源代码

    以下是一种使用CSS和HTML创建爱心的简单方法:这段代码将创建一个红色的爱心。你可以通过更改background颜色属性来改变爱心的颜色,通过更改width和height来改变爱心的大小。 二、复杂的HTML和CSS代码,可以创建一个...

    关于OPENGL的一段学习代码

    只是一段学期初学习OPENGL时编写的小代码,当中也是遇到了许多问题,也参考了许多大神的资料,代码不长希望可以给大家一点帮助

    PerCM个人代码管理软件

    经过一段时间的修改,现在代码很糟糕,是到了改对其进行修整的时候了。好看的代码,将是更为宝贵的财富。更何况这里编写的是用于资料统计的工具了? 进行重构的时候,发现自己还是有想法的。的确创新不是无本之源,...

    ASPNET学习积累的代码段

    该上传项是搜集了长时间的经验代码,包含了WEB编程的各种模块代码,其中许多模块可用于二次开发重复用,方法都封装好了,对于新手编程非常有用

    matlab不运行一段代码-portfolio:文件夹

    matlab不运行一段代码耿 超参数优化 机器学习中算法的许多参数的调整是一个难题。 除了蛮力方法外,更精致的解决方案也越来越受欢迎,这使人们希望能够更快地找到最佳超参数。 我对这些方法的兴趣已被诸如此类的...

    matlab不运行一段代码-getting-started:入门

    matlab不运行一段代码入门 您应该采取一些步骤来为您的项目准备好计算机。 设置计算机以处理项目 我们竭尽所能帮助您使入门变得尽可能容易。 完成后,以下内容为您提供了一些开始使用Python的指导: 学习使用Python ...

    Android高级编程--源代码

    该资料是《Android高级编程》的源代码 对应的书籍资料见: Android高级编程 基本信息 原书名: Professional Android Application Development 原出版社: Wrox 作者: (英)Reto Meier 译者: 王鹏杰 霍建同 出版社...

    Snippet Compiler 3.0.2 老朽痴拙汉化版(代码段编译器)

    Snippet Compiler3.0.2 老朽痴拙汉化版是一个免费的 .NET 编译...程式码自动缩排,包括 #region 收合的功能也有支援支援许多 Visual Studio 中既有的快速键 可选用 C# 或 VB.NET 编译器 编译错误的时候支援 Errors 视窗

    模拟退火算法解决TSP问题MATLAB代码

    这段代码使用了模拟退火的思想解决TSP问题。在这个仿真实验中解决了自定义的20个城市的TSP问题,在设定合适参数后每次的运行中都能得到一个比较理想的结果。 Main.m文件是程序入口。 Data_file.m文件设置自定义的...

    matlab把一段代码全作为注释-BestLeetCode:这是在LeetCode.com上解决问题的非正式解决方案,我们寻求最佳性能,希望有

    matlab把一段代码全作为注释BestLeetCode 它是什么? 这是针对LeetCode.com中的问题集的非正式FAST(est)C ++解决方案。 我们希望该存储库可以帮助人们编写灵活的程序。 警告:此存储库以速度为目标。 有些解决方案...

    python-snippets:Python代码段

    尽管可以通过Google,Stack Overflow或Python库文档轻松找到许多等效的代码段,但是这些代码段已以首选的编码样式编写,并且其中一些代码段旨在协同工作。 另外,还为代码片段提供了一些单元测试,这些代码片段通常...

    代码大全中文版

    许多程序仍然是错误百出,充斥着过时的技术,从而无法满足用户需要。软件工业界和学术界的研究者们,基本上已经解决了七十年代和八十年代在编程中遇到的问题,并发展了相应的技术。但是直到现在,这些技术中的大部分...

    Python情人节主题爱心代码及使用介绍.docx

    情人节,作为表达爱意、...你可以根据自己的需要,修改这段代码,将祝福语换成自己想说的话。 二、代码实现 下面是具体的代码实现过程: 1. 导入Turtle库 首先,我们需要导入Python的Turtle库,以便使用其中的绘图函

    popkit:此仓库包含许多配置脚本,代码段,可在您需要的任何地方使用

    此仓库包含许多配置脚本和代码段,可在服务器和台式机中使用。 用法 ./configure-使用此仓库配置本地计算机 ./configure -c-收集本地配置文件 SUBREPO 按字母顺序排列。 七彩Web emacs样式浏览器 doc 此subrepo...

    hoard:for适用于用PHP编写的团队的简单开源代码段管理器-Open source php source code

    专为团队设计的代码段管理器。 Hoard是使用PHP内置的代码段管理器。 它是为团队设计的,但也可以由个人使用! 通过完美组织的即时访问最常用的代码来增强您的工作流程。 最新发布的即将推出 特征 Hoard具有许多...

    WinRaR破译脚本代码(vbs版爆经典)

    WinRAR是大家常用的压缩工具,它的加密功能更是受到大家的青睐;这里做的是vbs脚本版的,很小巧实用。 技术含量: ...还有许多这里不一一说明了,大家一下就明了了... 这里也先感谢大家的支持了...

    matlab隐藏多行代码-GNUplot:使用VB.NET制作gnuplot图形,包括传递数组(数据)并使用“保持”以具有多层图形

    matlab隐藏多行代码GNUplot 致谢 此存储库中的初始项目代码改编自@AwokeKnowing的原始作品: 概述 大多数带有图形的科学出版物都使用gnuplot。 它的文档非常丰富,可以使用简单的数学语法以及简单的基于文本的数据...

    无需重启生产环境热更新代码HotSwapAgent.zip

    但开发期间的保存和重新加载应该是标准的,许多其他语言(包括 C#)都包含此功能。要高效的开发 Java 代码,必须要让 Java 像 JavaScript 一样,修改过的代码可以实时的反应出来。该项目 — Hotswap Agent 允许...

Global site tag (gtag.js) - Google Analytics