??xml version="1.0" encoding="utf-8" standalone="yes"?> public class Jsry implements java.io.Serializable { // Constructors /** default constructor */ /** full constructor */ public JsryId getId() { public void setId(JsryId id) { public void save(Jsry jsry) { public void delete(Jsry jsry) { public Jsry findById(com.insigma.hr.eduj.jsry.model.JsryId id) { public static void main(String[] args) { Jsry jsry = new Jsry();
]]>
针对上面的角色h员表如何用hibernate实现映射关系呢,因ؓ此表中的两个字段是其它两表中主键Q在本表中即使是主键又是外键Q下面说明一下操作这张表?br />W一步:首先生成员工信息表和角色理表的javaBean?hbm.xml文gQ这个是单表Q这里不多讲Q?br /> com.insigma.hr.eduj.ygxx.model.Ygxx.javaQ?br /> com.insigma.hr.eduj.ygxx.model.Ygxx.hbm.xml
com.insigma.hr.eduj.jsgl.model.Jsgl.java,
com.insigma.hr.eduj.jsgl.model.Jsgl.hbm.xml
保证员工信息表和角色理表能正常操作数据库(增,修,删,查)Q?br />W二步:生成角色人员表对应的映射文g如下Q?br /> 1).Jsry.hbm.xml文g内容如下Q?div style="padding: 4px 5px 4px 4px; border: 1px solid rgb(204, 204, 204); width: 98%; font-size: 13px; word-break: break-all; background-color: rgb(238, 238, 238);"><?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.insigma.hr.eduj.jsry.model.Jsry" table="jsry" catalog="hr">
<composite-id name="id" class="com.insigma.hr.eduj.jsry.model.JsryId">
<key-many-to-one name="jsgl" class="com.insigma.hr.eduj.jsgl.model.Jsgl">
<column name="JSBH" />
</key-many-to-one>
<key-many-to-one name="ygxx" class="com.insigma.hr.eduj.ygxx.model.Ygxx">
<column name="YGBH" length="20" />
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>
2).JsryId.javaq个javabean中存放了两个属性分别对应员工信息和角色理表的javabean对象Q内容如下:
public class JsryId implements java.io.Serializable {
private Jsgl jsgl;
private Ygxx ygxx;
public Jsgl getJsgl() {
return jsgl;
}
public void setJsgl(Jsgl jsgl) {
this.jsgl = jsgl;
}
public Ygxx getYgxx() {
return ygxx;
}
public void setYgxx(Ygxx ygxx) {
this.ygxx = ygxx;
}
}
3Q?Jsry.javaq个javabean中只有一个属性,是我们上面刚才新徏的JsryIdq个cd象;内容如下Q?br />
private JsryId id;
public Jsry() {
}
public Jsry(JsryId id) {
this.id = id;
}
return id;
}
this.id = id;
}
}
log.debug("saving Jsry instance");
try {
getHibernateTemplate().saveOrUpdate(jsry);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
log.debug("deleting Jsry instance");
try {
getHibernateTemplate().delete(jsry);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
log.debug("getting Jsry instance with id: " + id);
try {
Jsry instance = (Jsry) getHibernateTemplate().get(
"com.insigma.hr.eduj.jsry.model.Jsry", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List getJsgllist(String sql) {
String sqls = "select t.* from Jsgl t where 1=1 " + sql;
SQLQuery query = getHibernateTemplate().getSessionFactory()
.getCurrentSession().createSQLQuery(sqls);
query.addEntity("t", Jsry.class);
List topList = query.list();
return topList;
}
W四步:试
// TODO Auto-generated method stub
ApplicationContext appContext = new FileSystemXmlApplicationContext("/src/applicationContext.xml");
JsryService jsryService=(JsryService) appContext.getBean("jsryService");
JsryId id = new JsryId();
Jsgl jsgl = new Jsgl();
jsgl.setJsbh(1);
Ygxx ygxx = new Ygxx();
ygxx.setYgbh("1");
id.setYgxx(ygxx);
id.setJsgl(jsgl);
jsry.setId(id);
jsryService.save(jsry);
}
]]>package com.insigma.hr.comm;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import ognl.DefaultTypeConverter;
@SuppressWarnings("unchecked")
public class DateConverter extends DefaultTypeConverter {
public Object convertValue(Map context, Object value, Class toType) {
try {
if (toType == Date.class) { // 如果惌{换的是Datecd时将做以下操?br />
// 因ؓ在Struts2里会表单传过来的非字W串数据转换为String[],所以这里得取第一个?/span>
String dataStr = ((String[]) value)[0];
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); // 转换己想要日期格?/span>
return f.parse(dataStr);
} else if (toType == String.class) {
String dataStr = ((Date) value).toString();
return dataStr;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
W二步:?WEB-INF/classes文g夹(srcQ下创徏一个叫Qxwork-conversion.properties的文?br />
W三步:在里面添加一句话
java.util.Date=com.insigma.hr.comm.DateConverterQ指上面新徏的类Q?br />
然后重启pȝOK了?
那么在将数据提交到后台时Q便后自动的对应的Stringcd的数据{换成Datecd了?
]]>
]]>
然后在控制台执行以下命o
C:\lib
java -classpath ".;commons-logging-1.0.4.jar;axis.jar;commons-discovery-0.2.jar;jaxrpc.jar;wsdl4j-1.5.1.jar;
saaj.jar;activation.jar;mail.jar" org.apache.axis.wsdl.WSDL2Java -o "abcdefg"
http://10.10.10.111/WebService/ManageUsersService.asmx?wsdl
׃相应目录下生成相应的javac?然后把这些类拷到你的工程目录?
把Axis?个包加入到工E中,可以像一般类一栯用WebService?
调用Ҏ: ManageUsersService adcInterface = new ManageUsersServiceLocator();
ManageUsersServiceSoap soap = adcInterface.getManageUsersServiceSoap();
//以下p调用的方?/span>
int state = soap.getUserState("admin", "123456", "UC405297917");
?要保?a >http://10.10.10.111/WebService/ManageUsersService.asmx?wsdl
?可以在浏览器中测试?img src ="http://www.aygfsteel.com/senlin-blog/aggbug/168478.html" width = "1" height = "1" />
]]>
W二?pȝ初始化是所有服务名和\径加载到一个静态的HashMap?br />
W三?定义一个接口类
用览器后退之方法比?
history只有back forward和goҎ history.length 改写以上ҎQ没?br />location.replace 在该늚头部加上 Response.Expires = 0 Response.ExpiresAbsolute = Now - 1 Response.AddHeader "progma", "no-cache" Response.AddHeader "cache-control", "private" Response.CacheControl = "no-cache" 使该面讉K?后退卛_?br /> |
}
//删除cookie
function deleteCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null)
document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
//checkbox全不?br>function checkboxNoAll(itemName)
{
var item = document.getElementsByName(itemName);
for (var i=0; i<item.length; i++)
{
item[i].checked = false;
}
}
//checkbox中选择一?br>function checkCount(itemName)
{
var intCount=0;
var item = document.getElementsByName(itemName);
if (item.length>1){
for(i=0;i< item.length;i++)
{
if(item[i].checked)
intCount=intCount+1;
}
} else {
if(item[0].checked)
intCount++;
}
return intCount;
}
1. logger的level低Q表Clogger详l?br> 2. logging request的level高Q表Clogging request优先输?/p>
LevelcM预定义了五个levelQ它们的大小关系如下Q?br>Level.DEBUG < Level.INFO < Level.WARN < Level.ERROR < Level.FATAL
在代码中打印日志
W一步是取得LOGQLOG采用APACHE的COMMON-LOGGING包来获得?br>protected static Log log = LogFactory.getLog(XXX.class);
W二步就是LOG的输出,LOG输出只需要填写描q性文字,不要在LOG输出中包含Q何类名,旉Q日志别等信息。输出LOG时必L当前LOG的输出配|情c?br>if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() +
"' data sources");
}
修改LOG配置文gQ打印自己模块的LOG
在系l的configs目录下,已经有了~省的LOG4J配置文glog4j.properties?br>~省配置下包括了打印IBATIS和JDBC执行情况
# JDBC logging configuration...
log4j.logger.com.ibatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.org.springframework.jdbc.core=DEBUG
如果惌录自q开发类的日志,可以单的增加一?br>log4j.logger.com.spsoft.sample.service=DEBUG
log4j.logger.com.spsoft.sample.service.dao.SampleDao=INFO
com.spsoft.sample.service是包名,当然也可以直接指定类名?br>
import java.util.Date;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* 发送普通邮Ӟ接受普通邮?发送带有附件的邮gQ接收带有附件的邮g 发送html形式的邮Ӟ接受html形式的邮?发送带有图片的邮g{做了一个ȝ?br> */
public class sendmail {
private String host = "smtp.163.com";
private String username = "myshiyh";
private String password = "123456";
private String mail_head_name = "this is head of this mail";
private String mail_head_value = "this is head of this mail";
private String mail_to = "myshiyh@126.com";
private String mail_from = "myshiyh@163.com";
private String mail_subject = "this is the subject of this test mail";
private String mail_body = "this is the mail_body of this test mail";
private String personalName = "我的邮g";
public sendmail() {
}
/**
* 此段代码用来发送普通电子邮?br> */
public void send() throws SendMailException {
try {
Properties props = new Properties(); // 获取pȝ环境
Authenticator auth = new Email_Autherticator(); // q行邮g服务器用戯?br> props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, auth);
// 讄session,和邮件服务器q行通讯?br> MimeMessage message = new MimeMessage(session);
message.setContent("Hello", "text/plain"); // 讄邮g格式
message.setSubject(mail_subject); // 讄邮g主题
message.setText(mail_body); // 讄邮g正文
message.setHeader(mail_head_name, mail_head_value); // 讄邮g标题
message.setSentDate(new Date()); // 讄邮g发送日?br> Address address = new InternetAddress(mail_from, personalName);
message.setFrom(address); // 讄邮g发送者的地址
Address toAddress = new InternetAddress(mail_to); // 讄邮g接收方的地址
message.addRecipient(Message.RecipientType.TO, toAddress);
Transport.send(message); // 发送邮?br> System.out.println("send ok!");
} catch (Exception ex) {
ex.printStackTrace();
throw new SendMailException(ex.getMessage());
}
}
/**
* 用来q行服务器对用户的认?br> */
public class Email_Autherticator extends Authenticator {
public Email_Autherticator() {
super();
}
public Email_Autherticator(String user, String pwd) {
super();
username = user;
password = pwd;
}
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
}
public static void main(String[] args) {
sendmail sendmail = new sendmail();
try {
sendmail.send();
}
catch (Exception ex) {
}
}
}
asheet.setColumnView(0, 12);
asheet.setColumnView(1, 12);
asheet.setColumnView(2, 8);
asheet.setColumnView(3, 8);
asheet.setColumnView(4, 8);
asheet.setColumnView(5, 8);
asheet.setColumnView(6, 8);
asheet.setColumnView(7, 7);
asheet.setColumnView(8, 7);
asheet.setColumnView(9, 7);
asheet.setColumnView(10, 7);
asheet.setColumnView(11, 7);
asheet.setColumnView(12, 7);
asheet.setColumnView(13, 7);
asheet.setColumnView(14, 7);
/* 开始写入xls文g */
// 导出excel文g标题
Label labelC = new Label(0, 0, "处理信息l计?, wchB);
asheet.addCell(labelC);
// 合ƈW一?6个单元格?个作为标题栏
asheet.mergeCells(0, 0, 15, 0);
// 讄表头
labelC = new Label(0, 1, "预报信息", tTitle);
asheet.addCell(labelC);
asheet.mergeCells(0, 1, 3, 1);
labelC = new Label(0, 2, "查场", tTitle);
asheet.addCell(labelC);
labelC = new Label(1, 2, "车型", tTitle);
asheet.addCell(labelC);
labelC = new Label(2, 2, "车号", tTitle);
asheet.addCell(labelC);
labelC = new Label(3, 2, "轴位及左?, tTitle);
asheet.addCell(labelC);
labelC = new Label(4, 1, "作业场处理信?, tTitle);
asheet.addCell(labelC);
asheet.mergeCells(4, 1, 15, 1);
labelC = new Label(4, 2, "预警U别", tTitle);
asheet.addCell(labelC);
labelC = new Label(5, 2, "查时?, tTitle);
asheet.addCell(labelC);
labelC = new Label(6, 2, "车次", tTitle);
asheet.addCell(labelC);
labelC = new Label(7, 2, "~组", tTitle);
asheet.addCell(labelC);
labelC = new Label(8, 2, "Z", tTitle);
asheet.addCell(labelC);
labelC = new Label(9, 2, "轮位", tTitle);
asheet.addCell(labelC);
labelC = new Label(10, 2, "轴号", tTitle);
asheet.addCell(labelC);
labelC = new Label(11, 2, "故障原因", tTitle);
asheet.addCell(labelC);
labelC = new Label(12, 2, "实际量数据", tTitle);
asheet.addCell(labelC);
labelC = new Label(13, 2, "量?, tTitle);
asheet.addCell(labelC);
labelC = new Label(14, 2, "复测?, tTitle);
asheet.addCell(labelC);
labelC = new Label(15, 2, "处理方式", tTitle);
asheet.addCell(labelC);
wwb.write();
wwb.close();
flag = true;
} catch (Exception e) {
flag = false;
e.printStackTrace();
}
return flag;
}
?1. 说明asheet.mergeCells(?, ?, ?, ?)合ƈ单元?起始都是0
2 . 在Bean中需要导入两个jar包servlet.jar和jxl.jar
修改地方Q?/p>
<Connector
port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIncoding="GBK"/>