java 配置jmstemplate_Spring JMSTemplate 与 JMS 原生API比较

JMSUtil与Spring JmsTemplate的对比

Author:信仰

Date:2012-4-20

未完待续,截止日期2012-4-20

从以下几方面比较JMSUtil和Spring JmsTemplate

l  对JNDI的支持

l  对ConnectionFactory、Connection、Destination、Session、MessageProducer、MessageConsumer对象的处理

l  对事务的处理

l  不同类型的消息处理

l  异常处理

Spring

JMSUtil

对JNDI的支持

支持,可配置,可编码

支持,只能编码

对ConnectionFactory、

Connection、

Destination、

Session、

MessageProducer、

MessageConsumer对象的处理

配置

编码

对事务的处理

配置

编码

对不同类型消息处理

自动转换

编码转换

异常处理

运行时异常,无需写try…catch

检查异常,必须写try…catch

1.   对JNDI的支持

两者都支持JNDI和非JNDI方式。两者的JNDI名称都是在XML中配置完成的,这一点上两者不存在谁更有优势。

1.1. Spring对JNDI的支持

1.1.1.    Spring JMS 实现

JNDI查询的JNDI模板配置

com.ibm.websphere.naming.WsnInitialContextFactory

iiop://127.0.0.1:2813/

通过JNDI配置JMS连接工厂

class="org.springframework.jndi.JndiObjectFactoryBean">

MQ_JMS_MANAGER

JMS模板配置

false

20000

把JmsTemplate绑定到应用程序中

用JmsTemplate发送JMS消息的JMSSender

public class JMSSender

{

private JmsTemplate102 jmsTemplate102;

public JmsTemplate102 getJmsTemplate102()

{

return jmsTemplate102;

}

public void setJmsTemplate102(JmsTemplate102 jmsTemplate102)

{

this.jmsTemplate102 = jmsTemplate102;

}

public void sendMesage()

{

jmsTemplate102.send("JMS_RequestResponseQueue", new MessageCreator()

{

public Message createMessage(Session session) throws JMSException

{

return session.createTextMessage("This is a sample message");

}

});

}

}

用JmsTemplate检索JMS消息的JMSReceiver(同步接收)

public class JMSReceiver

{

private JmsTemplate102 jmsTemplate102;

public JmsTemplate102 getJmsTemplate102()

{

return jmsTemplate102;

}

public void setJmsTemplate102(JmsTemplate102 jmsTemplate102)

{

this.jmsTemplate102 = jmsTemplate102;

}

public void processMessage()

{

Message msg = jmsTemplate102.receive("JMS_RequestResponseQueue");

try

{

TextMessage textMessage = (TextMessage) msg;

if ( msg != null )

{

System.out.println(" Message Received -->" + textMessage.getText());

}

}

catch ( Exception e )

{

e.printStackTrace();

}

}

}

1.2. JMSUtil对JNDI的支持

1.2.1.    JMSUtil的实现

XML配置:

${jms.logQueueConFactory}

${jms.errLogQueueName}

0

1

JMSUtil中发送消息报文和对象报文的方法:

public static void putTextMessage(MsgData msgData, boolean transacted) throwsMessageException

{

……

ConnectionFactory connectionFactory = null;

Connection connection = null;

Session session = null;

Destination destination = null;

MessageProducer messageProducer = null;

try

{

connectionFactory = (ConnectionFactory)

LocalContext.lookup(msgData.getQcfName(), true);

destination = (Destination) LocalContext.lookup(msgData.getOutputQ, false);

connection = connectionFactory.createConnection();

session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);

messageProducer = session.createProducer(destination);

// 修改为 二进制 ,字符集为可配置项,缺省为 GBK

BytesMessage message = session.createBytesMessage();

if (msgData.getExpirationTime() != null)

{

messageProducer

.setTimeToLive(msgData.getExpirationTime().longValue());

}

……

message

.writeBytes(msgData.getMsg()

.getBytes(MtoFactory.getInstance().getCharsetName()));

}

catch ( JMSException e1 )

{

String errorMsg = "发送消息失败:错误码" + e1.getErrorCode() + ",错误原因:" + e1.getMessage();

……

}

catch (NamingException e1)

{

String errorMsg = "发送消息失败,查找对应的资源未找到,错误原因:" + e1.getMessage();

……

}

catch ( UnsupportedEncodingException ue )

{

String errorMsg = "发送消息失败,不支持的字符集: " + MtoFactory.getInstance().getCharsetName();

log.error(errorMsg, ue);

throw new MessageException(errorMsg, ue);

}

catch (RuntimeException e)

{

String errorMsg = "发送消息失败:" + e.getMessage();

……

}

finally

{

if ( connection != null)

{

if( messageProducer != null)

{

try

{

messageProducer.close();

}

catch ( JMSException e2 )

{

log.error("关闭messageProducer异常", e2);

}

}

if( session != null)

{

try

{

session.close();

}

catch ( JMSException e2 )

{

log.error("关闭session异常", e2);

}

}

try

{

connection.close();

}

catch ( JMSException e2 )

{

log.error("关闭connection异常", e2);

}

}

}

}

/**

* 发送一条对象报文,将一个对象放入队列中

*

* @param qcfName

*            连接工厂名

* @param outputQ

*            队列名

* @param obj

*            要发送的对象

* @param transacted 是否参与事务

* @throws MessageException

*/

public static void putObjectMessage(String qcfName, String outputQ, Serializable obj,boolean transacted) throws MessageException

{

ConnectionFactory connectionFactory = null;

Connection connection = null;

Session session = null;

Destination destination = null;

MessageProducer messageProducer = null;

try

{

connectionFactory = (ConnectionFactory) LocalContext.lookup(qcfName, true);

destination = (Destination) LocalContext.lookup(outputQ, false);

connection = connectionFactory.createConnection();

session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);

messageProducer = session.createProducer(destination);

ObjectMessage objmsg = session.createObjectMessage(obj);

objmsg.setJMSType("transfer");

messageProducer.send(objmsg);

}

catch ( JMSException e1 )

{

String errorMsg = "发送消息失败:错误码" + e1.getErrorCode() + ",错误原因:" + e1.getMessage();

……

}

catch (NamingException e1)

{

String errorMsg = "发送消息失败,查找对应的资源未找到,错误原因:" + e1.getMessage();

……

}

catch ( UnsupportedEncodingException ue )

{

String errorMsg = "发送消息失败,不支持的字符集: " + MtoFactory.getInstance().getCharsetName();

log.error(errorMsg, ue);

throw new MessageException(errorMsg, ue);

}

catch (RuntimeException e)

{

String errorMsg = "发送消息失败:" + e.getMessage();

……

}

finally

{

if ( connection != null)

{

if( messageProducer != null)

{

try

{

messageProducer.close();

}

catch ( JMSException e2 )

{

log.error("关闭messageProducer异常", e2);

}

}

if( session != null)

{

try

{

session.close();

}

catch ( JMSException e2 )

{

log.error("关闭session异常", e2);

}

}

try

{

connection.close();

}

catch ( JMSException e2 )

{

log.error("关闭connection异常", e2);

}

}

}

}

2.  对ConnectionFactory、Connection、Destination、Session、MessageProducer、MessageConsumer的处理

Spring对打开和关闭连接的处理由容器控制,而JMS打开和关闭连接的处理由应用来控制。

2.1. JMSUtil对上述对象的处理

关闭上述对象:

finally

{

if ( connection != null)

{

if( messageProducer != null)

{

try

{

messageProducer.close();

}

catch ( JMSException e2 )

{

log.error("关闭messageProducer异常", e2);

}

}

if( session != null)

{

try

{

session.close();

}

catch ( JMSException e2 )

{

log.error("关闭session异常", e2);

}

}

try

{

connection.close();

}

catch ( JMSException e2 )

{

log.error("关闭connection异常", e2);

}

}

}

3.   对事务的处理

3.1. Spring JMSTemplate对事物的处理方式

3.1.1.    本地事务

Spring为JMS提供了本地事务管理的能力,JMS事务管理器和数据库事务管理器都是PlatformTransactionManager接口的实现类,Spring的org.springframework.jms.connection包提供了用于管理JMS本地事务JmsTransactionManager事务管理器,JMS1.0.2则对应JmsTransactionManager102。

class=”org.springframework.jms.connection.JmsTransactionManager”>

在进行标准的Spring事务配置后,就能够管理那些基于JmsTemplate编写的JMS处理类。对于那些未基于JmsTemplate编写的JMS处理类,可以让消息监听器容器对它们进行事务管理。DefaultMessageListenerContainer和ServerSessionMessageListenerContainer都支持通过消息监听器使用JMS事务,不过必须为他们提供一个事务管理器,如下配置:

class=”org.springframework.jms.connection.JmsTransactionManager”>

class=”org.springframeword.jms.listener.DefaultMessageListenerContainer”>

3.1.2.    JTA事务

启用JTA事务后,用户可以让数据库操作、JMS操作以及其它符合JTA标准的操作工作在同一个全局事务中。

对于JMS来说,用户必须从Java EE的JNDI中获取XA支持的JMS ConnectionFactory。

对于Spring配置来说,JTA全局事务和本地事务的差别并不大,用户只需要声明一个JtaTransactionManager事务管理器,将事务委托给Java EE应用服务器就可以了。当然,ConnectionFactory必须使用XA支持的JMSConnectionFactory。

下面是让一个数据源和一个JMSConnectionFactory工作于同一个JTA事务的具体配置:

class=”org.springframework.transaction.jta.JtaTransactionManager”/>

3.2. JMSUtil对事物的处理方式

3.2.1.    本地事务

在Session可以控制交易,首选Session要定义成transacted,然后通过调用commit或rollback来提交或者回滚事务。

QueueSession queueSession

= connection.createQueueSession(boolean transacted, int acknowledgeMode);

TopicSession topicSession

= connection.createTopicSession(Boolean transacted, int acknowledgeMode);

Session.commit();

Session.rollback()

注意:如果transacted = true,则acknowledgeMode的值便无关紧要。

3.2.2.    JTA事务

还不太了解……

4.   不同类型的消息的处理

JMS有多钟类型的消息:

l  javax.jms.TextMessage

l  javax.jms.MapMessage

l  javax.jms.ObjectMessage

l  javax.jms.BytesMessage

4.1. Spring使用消息转换器发送/接收消息

Spring将POJO和JMS消息的双向转换工作抽象到MessageConverter中,在JmsTemplate中提供了几个convertAndSend()和receiveAndConvert()方法,这些方法自动使用MessageConverter完成消息的转换工作。

4.1.1.    消息转换器

在org.springframework.jms.support.converter包中,Spring提供了消息转换器的支持,首先看一下MessageConverter接口的两个方法:

l  Object fromMessage(Message message)

l  Message toMessage(Object object, Session session)

MessageConverter接口的目的是为了向调用者屏蔽JMS细节,在JMS之上搭建的一个隔离层,这样调用者可以直接发送和接收POJO,而不是发送和接收JMS相关消息,调用者的程序将得到进一步简化。

JMS消息类型

POJO类型

javax.jms.TextMessage

String

javax.jms.MapMessage

java.util.Map

javax.jms.ObjectMessage

java.io.Serializable

javax.jms.BytesMessage

byte[] bytes

当转换发生错误时,Spring将抛出MessageConversionException异常,该异常是org.springframework.jms.JmsException的子类。

JmsTemplate和JmsTemplate102分别使用SimpleMessageConverter和SimpleMessageConverter102作为默认的消息转换器。用户也可以通过实现MessageConverter定义自己的消息转换器,并在配置JmsTemplate时通过messageConverter属性指定自己的消息转换器。

4.1.2.    发送POJO消息

4.1.2.1.       将POJO简单地映射为Message对象发送

假设User是一个POJO,其结构如下:

package com.baobaotao.domain;

……

public class User implement Serializable

{

private String username;

private String userId;

private String email;

private int level;

// 省略get/setter

}

这个POJO必须实现Serializable接口,以便可以将对象序列化后作为消息发送,除此以外没有任何其他的要求。

将User作为JMS消息发送的操作仅需要一行简单的代码就可以完成:

package com.baobaotao.jms;

……

import com.baobaotao.domain.User;

public class MessageSender extends JmsGatewaySupport

{

……

public void sendUserMsg(User user)

{

//发送User对象

super.getJmsTemplate.convertAndSend(“userMsgQ”, user);

}

}

JmsTemplate提供了几个重载版本的convertAndSend()方法:

l  convertAndSend

public void convertAndSend(Object message)

Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.

This will only work with a default destination specified!

Specified by:

Parameters:

message - the object to convert to a message

Throws:

JmsException - converted checked JMSException to unchecked

l  convertAndSend

public void convertAndSend(Destination destination,

Object message)

Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.

Specified by:

Parameters:

destination - the destination to send this message to

message - the object to convert to a message

Throws:

JmsException - converted checked JMSException to unchecked

l  convertAndSend

public void convertAndSend(String destinationName,

Object message)

Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.

Specified by:

Parameters:

destinationName - the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)

message - the object to convert to a message

Throws:

JmsException - checked JMSException converted to unchecked

l  convertAndSend

public void convertAndSend(Object message,

Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter. The MessagePostProcessor callback allows for modification of the message after conversion.

This will only work with a default destination specified!

Specified by:

Parameters:

message - the object to convert to a message

postProcessor - the callback to modify the message

Throws:

JmsException - checked JMSException converted to unchecked

l  convertAndSend

public void convertAndSend(Destination destination,

Object message,

Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. The MessagePostProcessor callback allows for modification of the message after conversion.

Specified by:

Parameters:

destination - the destination to send this message to

message - the object to convert to a message

postProcessor - the callback to modify the message

Throws:

JmsException - checked JMSException converted to unchecked

l  convertAndSend

public void convertAndSend(String destinationName,

Object message,

Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. The MessagePostProcessor callback allows for modification of the message after conversion.

Specified by:

Parameters:

destinationName - the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)

message - the object to convert to a message.

postProcessor - the callback to modify the message

Throws:

JmsException - checked JMSException converted to unchecked

4.1.2.2.       将POJO映射为Message后进行后置处理

通过以上方法发送POJO,JmsTemplate仅会按照简单的映射方式发送JMS消息,如果我们需要在此基础上进一步设置Message的Header和Properties部分的值,一种方法是编写自己的消息转换器达到目的,还有一种更好的方法是使用Spring的org.springframework.jms.core.MessagePostProcessor回调接口。JmsTemplate在使用MessageConverter将POJO转换为JMS消息后以及发送消息前,将调用MessagePostProcessor对JMS消息进行后置加工处理。因此,我们有机会通过一个自定义的MessagePostProcessor回调接口对JMS消息对象进行“修正性”工作。

下面,我们在User转换为ObjectMessage后,为消息对象指定过期时间并设置一个属性:

package com.baobaotao.jms;

……

import org.springframework。jms.core.MessagePostProcessor;

public class MessageSender extends JmsGatewaySupport

{

public void sendUserMsg2(final User user)

{

getJmsTemplate().convertAndSend(“userMsgQ”,

user,

new MessagePostProcessor()

{

public Message postProcessMessage(Message message) throws JMSException

{

message.setJMSExpiration(System.currentTimeMillis() + 60 * 60 * 1000); //设置过期时间:一小时后过期

message.setIntProperty(“level”, user.getLevel()); // 设置一个属性

}

});

}

}

4.1.3.    接收POJO消息

4.2. JMSUtil必须直接实例化不同类型的消息对象

4.2.1.    发送消息

例如,如果要发送的消息是javax.jms.TextMessage类型,代码如下所示:

TextMessage txtMsg = queueSession.createTextMessage(obj);

messageProducer.send(txtMsg);

4.2.2.    接收消息

例如,如果要接收的消息是javax.jms.TextMessage类型,代码如下所示:

Message m = messageConsumer.receive(1000 * 1);

if ( m instanceof TextMessage )

{

TextMessage textMessage = (TextMessage) m;

System.out.println(textMessage.getText());

}

5.   异常处理

5.1. Spring JmsTemplate 运行时异常

JMS的异常都是检查型异常,使用原生JMS API,用户需要提供繁琐的异常捕获代码。而Spring将检查型异常转化为运行期异常。

Spring在org.springframework.jms包为javax.jms包中所有的异常类提供了类型转换的镜像实现。如:org.springframework.jms.IllegalStateException对应javax.jms.IllegalStateExceptipn;org.springframework.jms.InvalidClientIDException对应javax.jms.InvalidClientIDException等。Spring中所有JMS相关的异常都继承于JmsException类。

此外,Spring还提供了一些特定的JMS异常类:

l  DestinationResolutionException:Spring允许通过简单的字符串指定消息地址,DestinationResolver在解析消息地址发生错误时抛出异常;

l  SynchedLocalTransactionFailedException:如果在同步本地事务发生异常时抛出该异常,由于事务已经结束后,再次尝试同步事务时会发生这个异常;

l  UncategorizedJmsException:任何未被归类的其他类型一场。

5.2. JMSUtil检查异常

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/572785.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java微信支付必要参数_微信支付 开发账号体系各参数详解

商户在微信公众平台提交申请资料以及银行账户资料,资料审核通过并签约后,可以获得表6-4所示帐户(包含财付通的相关支付资金账户),用于公众帐号支付。帐号及作用:appid :公众帐号身份的唯一标识。审核通过后&#xff0c…

MyEclipse10的正确破解方法

无法转载,故给出原文链接,以供需要者。 MyEclipse10的正确破解方法转载于:https://www.cnblogs.com/qbzf-Blog/p/6341400.html

【二分法】- leetcode

275. H-Index II 278. First Bad Version 此题的条件必须是left < right, 否则如果只有一个版本的话&#xff0c;一直跳不出循环&#xff0c; time limitation。转载于:https://www.cnblogs.com/93scarlett/p/6353765.html

mysql referential_constraints_hibernate4.3.8与spring mvc结合遇到的问题

2703 [2015-01-21 16:47:42 ] - [ip, ref, ua, sid]WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1109, SQLState: 42S022703 [2015-01-21 16:47:42 ] - [ip, ref, ua, sid]ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Unknown table ‘referential_constraints‘ in …

ie11浏览器可以下载java吗_解析:WindowsXP系统能否安装IE11浏览器

现在&#xff0c;IE浏览器可以称得上是市场占有率最高的一款网页浏览器。因为windowsxp是一款比较久的操作系统&#xff0c;所以很多用户都会疑惑在xp上是否能够安装最新版的ie11浏览器。下面&#xff0c;小编就给大家详细解答下该问题。很遗憾的告诉大家&#xff0c;Windows X…

centos uninstall teamviewer11

由于某些原因&#xff0c;centos系统上的teamviewer不能运行。一直没有管它&#xff08;懒&#xff09;。 但是&#xff0c;突然看不下去了。因为每次开机后都自动启动&#xff0c;需要关闭&#xff0c;否则有问题。所以&#xff0c;uninstall。 尝试了很多都失败。尝试的步骤是…

java ajax传输图片_Java使用Ajax实现跨域上传图片功能

说明 &#xff1a;图片服务器是用Nginx搭建的&#xff0c;用的是PHP语言这个功能 需要 用到两个js文件&#xff1a;jquery.js和jQuery.form.jsfunction submitImgSize1Upload() {var postData function( form , callback){var form document.getElementById("upload-for…

opencv调节图片饱和度_OpenCV调整彩色图像的饱和度和亮度

问题如何调整彩色图像的饱和度和亮度解决思路详细步骤&#xff1a;将RGB图像值归一化到[0, 1]然后使用函数cvtColor进行色彩空间的转换接下来可以根据处理灰度图像对比度增强伽马变换或者线性变换调整饱和度和亮度分量最后转换到RGB色彩空间代码# !/usr/bin/env python# -*-enc…

Java并发——线程中断学习

1. 使用interrupt()中断线程当一个线程运行时&#xff0c;另一个线程可以调用对应的Thread对象的interrupt()方法来中断它&#xff0c;该方法只是在目标线程中设置一个标志&#xff0c;表示它已经被中断&#xff0c;并立即返回。这里需要注意的是&#xff0c;如果只是单纯的调用…

python etree创建xml_Python构建XML树结构的实例教程

这篇文章主要介绍了Python构建XML树结构的方法,结合实例形式分析了Python创建与打印xml数结构的实现步骤与相关操作技巧,需要的朋友可以参考下本文实例讲述了Python构建XML树结构的方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;1.构建XML元素#encodingutf-8from…

分布式服务框架原理(一)设计和实现

分布式服务框架设计 分布式服务框架一般可以分为以下几个部分&#xff0c; &#xff08;1&#xff09;RPC基础层&#xff1a; 包括底层通信框架&#xff0c;如NIO框架、通信协议&#xff0c;序列化和反序列化协议&#xff0c;以及在这几部分上的封装&#xff0c;屏蔽底层通信细…

or函数 java_Java OptionalInt orElseGet()用法及代码示例

orElseGet(java.util.function.IntSupplier)方法可帮助我们获取此OptionalInt对象中的值。如果此OptionalInt中不存在值&#xff0c;则此方法返回提供函数产生的结果&#xff0c;并作为参数传递用法:public int orElseGet(IntSupplier supplier)参数&#xff1a;此方法接受提供…

ADO.NET高级应用

ADO.NET事务处理(4个步骤) 1.调用SqlConnection对象的BeginTransaction()方法&#xff0c;创建一个SqlTransaction对象&#xff0c;标志事务开始。 2.将创建的SqlTransaction对象分配给要执行的SqlCommand的Transaction属性。 3.调用相应的方法执行SqlCommand命令。 4.调用SqlT…

php日常收获

php1、sprintf 用法&#xff08;晚上写成blog w3cschool可查&#xff09;2、使用thinkphp getfield 方法时只查询一个字段默认返回第一条数据&#xff0c;如果想要返回数组需要写成&#xff1a;$this->getField(id,true); // 获取id数组3、数据分页时配合limit&#xff08;x…

java dfs算法蓝桥杯题_【蓝桥杯省赛JavaB组真题详解】四平方和(2016)_疼疼蛇的博客-CSDN博客...

原文作者&#xff1a;疼疼蛇原文标题&#xff1a;【蓝桥杯省赛JavaB组真题详解】四平方和(2016)发布时间&#xff1a;2021-02-26 15:00:01题目描述四平方和四平方和定理&#xff0c;又称为拉格朗日定理&#xff1a;每个正整数都可以表示为至多4个正整数的平方和。如果把0包括进…

Spring JdbcTemplate查询实例

这里有几个例子向您展示如何使用JdbcTemplate的query()方法来查询或从数据库提取数据。整个项目的目录结构如下&#xff1a;1.查询单行数据这里有两种方法来查询或从数据库中提取单行记录&#xff0c;并将其转换成一个模型类。1.1 自定义RowMapper 在一般情况下&#xff0c;它总…

访问php文件显示500错误,nginx 访问.php文件正常,访问.html文件500错误

#php解析需要配置以下参数181 location ~ \.php|\.html$ {把下面的一行修改为上面的&#xff0c;重启nginx服务器。182 #location ~ \.php$ {183 #root /var/www;184 fastcgi_pass 127.0.0.1:9000;185 fastcgi_index index.php;186 #fastcgi_param SCRIPT_FILENAME /scripts$fa…

下面哪个进制能表述 13*16=244是正确的?)[中国台湾某计算机硬件公司V2010年5月面试题]...

A&#xff0e;5B&#xff0e;7C&#xff0e;9D&#xff0e;11解析&#xff1a;13如果是一个十进制的话&#xff0c;它可以用131*1013*100来表示。现在我们不知道13是几进制&#xff0c;那我们姑且称其X进制。X进制下的13转化为十进制可以用131*X13*X0;表示&#xff1b;X进制下的…

AngularJS中页面传参方法

1、基于ui-router的页面跳转传参 (1) 用ui-router定义路由&#xff0c;比如有两个页面&#xff0c;一个页面(producers.html)放置了多个producers&#xff0c;点击其中一个目标&#xff0c;页面跳转到对应的producer页面&#xff0c;同时将producerId这个参数传过去。 .state(p…

php注册树模式,PHP设计模式之详记注册树模式

一、什么是注册树模式注册树模式又叫注册模式、注册器模式。注册树模式是将经常使用到的对象实例挂到一颗全局的树上&#xff0c;需要使用时从数树上取出即可。举个栗子&#xff1a;有一个空的工具箱。需要维修东西&#xff0c;因此买了扳手和螺丝刀等工具&#xff0c;将它们放…