我正在尝试解决如何将 XML 文档解组为 Java 文档。xml文档的顶部是这样的
<xs:myData xmlns:xs="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com example.xsd ">
Run Code Online (Sandbox Code Playgroud)
有一个架构文件,其顶部如下所示:
<schema targetNamespace="http://www.example.com"
elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.example.com">
Run Code Online (Sandbox Code Playgroud)
我想使用 Spring/JaxB 解组 xml 文档并最终将其转换为 JPA 对象。我不知道如何去做,所以我在谷歌上寻找例子并想出了这个http://thoughtforge.net/610/marshalling-xml-with-spring-ws-and-jaxb/
除了如何或在何处使用模式之外,我了解其中的大部分内容。
我看过其他明确指定架构的例子,即
SchemaFactory schemaFac = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema sysConfigSchema = schemaFac.newSchema(
new File("example.xsd"));
unmarshaller.setSchema(sysConfigSchema);
RootElement root = (RootElement)unmarshaller.unmarshal(
new File("example1.xml"));
Run Code Online (Sandbox Code Playgroud)
我希望能有更多示例展示 Spring/REST 与架构验证的解组。
谢谢
我有一个XML文档,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xs:msgdata xmlns:xs="http://www.myCompany.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.myCompany.com msgdata.xsd">
<xs:msgid>MsgID001</xs:msgid>
<xs:msgHash>hlkJKLHljkhkjlHKJLHkjl6y987HJKH</xs:msgHash>
</xs:msgdata>
Run Code Online (Sandbox Code Playgroud)
还向我发送了一个模式文档(称为msgdata.xsd).我正在使用JAXB将上述xml文档解组为Java对象.解组代码如下所示:
final JAXBContext context = JAXBContext.newInstance(clazz);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File("C:\\temp\\msgdata.xsd"));
final Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);
return (T) unmarshaller.unmarshal(new StringReader(xml));
Run Code Online (Sandbox Code Playgroud)
XML的目标对象如下所示(然后将对象转换为休眠实体.
@XmlRootElement(name = "msgdata")
public class Message {
private String msgid;
private String msgHash;
@XmlElement(name = "msgid")
public String getMsgid() {
return msgid;
}
public void setMsgid(String msgid) {
this.msgid = msgid;
}
@XmlElement(name = "msgHash")
public String getMsgHash() {
return msgHash;
} …Run Code Online (Sandbox Code Playgroud) 环境:
Jboss 7.1.0 OS Windows
我正在尝试一个简单的测试,使用Jboss和内置的HornetQ JMS提供程序来试用JMS.经过大量的游戏后,我设法得到了这种配置的响应
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "appuser2");
env.put(Context.SECURITY_CREDENTIALS, "s3cr3t");
Run Code Online (Sandbox Code Playgroud)
但问题是,当我运行它时,我收到以下错误:
javax.jms.JMSSecurityException: Unable to validate user: null
at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:286)
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:695)
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSession(ClientSessionFactoryImpl.java:264)
at org.hornetq.jms.client.HornetQConnection.authorize(HornetQConnection.java:589)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:694)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
at com.jms.client.ConsoleClient.runExample(ConsoleClient.java:51)
at com.jms.client.ConsoleClient.main(ConsoleClient.java:20)
Caused by: HornetQException[errorCode=105 message=Unable to validate user: null]
... 9 more
Run Code Online (Sandbox Code Playgroud)
我一直在寻找谷歌,每个例子似乎都指向如何配置HornetQ作为独立服务器的安全设置.我无法弄清楚如何在Jboss上配置用户以及我是否需要.
有任何想法吗?
我有一个要求,我需要配置一个基于Spring的应用程序来使用两个数据库.我们有两个数据库,一个用于保存实时数据,另一个数据库用作数据仓库,包含存档数据(其结构与Live db完全相同).
为简单起见,假设有搜索产品的请求.应用程序应该做的是在Live数据库中搜索产品详细信息,如果没有找到,它将检查存档数据库.
如果我需要配置这样的设置,我是否仍然需要配置数据源,搜索代码是否必须使用第一个数据源来检查实时数据库,如果没有找到它将使用存档数据库运行另一个查询?
以上可能是可行的,但我想知道是否有更好的方法来做到这一点.例如,应用程序是否可以在单个数据源上工作,即使它在幕后实际上与两个数据库一起工作?
该应用程序基于Spring,JPA/Hibernate,SOAP和Mysql数据库以及Jboss 7作为应用程序服务器.
显示如何使用Spring和Jboss配置它的任何示例都非常有用.
谢谢
我如何在以下jdbctemplate示例中指定'age'参数的值?
String sql = "SELECT * FROM CUSTOMER where age = ? ";
List<Customer> customers = new ArrayList<Customer>();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
List<Map> rows = jdbcTemplate.queryForList(sql);
for (Map row : rows) {
Customer customer = new Customer();
customer.setCustId((Long)(row.get("CUST_ID")));
customer.setName((String)row.get("NAME"));
customer.setAge((Integer)row.get("AGE"));
customers.add(customer);
}
return customers;
Run Code Online (Sandbox Code Playgroud) 我有以下架构:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:m="http://ws.mypackage.com"
xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified"
targetNamespace="http://ws.mypackage.com"
attributeFormDefault="unqualified">
<xs:element name="downloadMessageRequestSaaj">
<xs:complexType/>
</xs:element>
<xs:element name="downloadMessageRequest">
<xs:complexType/>
</xs:element>
<xs:element name="downloadMessageResponseSaaj" type="m:downloadResponseSaajType" />
<xs:complexType name="downloadResponseSaajType">
<xs:sequence>
<xs:element name="requestName" type="xs:string"/>
<xs:element name="payLoad">
<xs:complexType>
<xs:sequence>
<xs:element name="messagePayLoad" type="xs:base64Binary" xmime:expectedContentTypes="multipart/related"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="downloadMessageResponse" type="m:downloadResponseType" />
<xs:complexType name="downloadResponseType">
<xs:sequence>
<xs:element name="requestName" type="xs:string"/>
<xs:element name="payLoad">
<xs:complexType>
<xs:sequence>
<xs:element name="messagePayLoad" type="xs:base64Binary" xmime:expectedContentTypes="multipart/related"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="localDTMRequest">
<xs:complexType/>
</xs:element>
<xs:element name="localDTMResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="localDTM" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> …Run Code Online (Sandbox Code Playgroud) 是否可以为同一个XSLT样式表使用不同的HTML布局?
我一直在阅读XSLT,我看到的大多数示例都表明HTML代码实际上是嵌入在样式表中的.
是否可以将相同的样式表用于多个HTML布局?(我的想法类似于Velocity的工作原理 - 即可以使用相同的Velocity标签处理多个HTML文件).
我正在使用Java Xalan处理器来处理XSLT.
我在下面尝试过@Dimitre Novatchev方法,它完美无缺.唯一的问题是我如何处理循环元素?例如,如果将xml文档修改为:
<person>
<fname>John</fname>
<lname>Smith</lname>
<age>25</age>
<age>33</age>
<age>55</age>
</person>
Run Code Online (Sandbox Code Playgroud)
我如何遍历每个年龄元素?
这是我在HTML模板上尝试但我没有看到任何区别:
<html xmlns:gen="my:tranform-generated">
<body>
<h1>Hi <gen:fname/> <gen:lname/>!</h1>
You are <gen:age/> years old.
<gen:for-each select="/person/age">
<gen:age/>,
</gen:for-each>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
预期产出
我想要上面的输出
Hi JohnSmith!
You are 25 years old.
25, 33, 55
Run Code Online (Sandbox Code Playgroud) 我是Swing的新手,但有点努力实现我想做的事情.我想构建一个如下所示的屏幕:

我不确定哪种布局最适合这种屏幕.我尝试使用BorderLayout但它永远不会出现.我得到了右下方的按钮,但中间的组件证明是非常具有挑战性的.我知道如何将组件添加到面板上,但我正在努力的区域是如何对齐它们.有时如果我在带有BORDERLAYOUT的面板上添加文本字段,它会占用我不想要的整个面板的整个空间.
我设法让它几乎使用AbsoluteLayout工作,但我怀疑这不是最好的选择,如果我希望屏幕流畅.
setBounds(100, 100, 775, 599);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(SystemColor.control);
contentPanel.setForeground(Color.RED);
contentPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(new BorderLayout(0, 0));
{
JPanel topHeadersPanel = new JPanel();
contentPanel.add(topHeadersPanel, BorderLayout.NORTH);
topHeadersPanel.setLayout(new BorderLayout(0, 0));
{
JLabel lblSetSourceRecord = new JLabel("Source customer record:");
lblSetSourceRecord.setFont(new Font("Tahoma", Font.BOLD, 12));
topHeadersPanel.add(lblSetSourceRecord, BorderLayout.WEST);
}
{
JLabel lblSetDestinationRecord = new JLabel("Destination customer record:");
lblSetDestinationRecord.setFont(new Font("Tahoma", Font.BOLD, 12));
topHeadersPanel.add(lblSetDestinationRecord, BorderLayout.EAST);
}
{
JLabel lblSetDestinationRecord = new JLabel("Source customer:");
lblSetDestinationRecord.setFont(new Font("Tahoma", Font.BOLD, 12));
topHeadersPanel.add(lblSetDestinationRecord, BorderLayout.SOUTH);
}
}
{
JPanel buttonPane = …Run Code Online (Sandbox Code Playgroud) 在以下示例中,
variable recordId number;
BEGIN
SELECT MAX(recordvalue)
INTO recordId
FROM sometable;
END;
PRINT recordid;
SELECT *
FROM someothertable
WHERE recordkey = &recordId;
Run Code Online (Sandbox Code Playgroud)
最后一行的select语句无法访问recordId的值.我知道我可以recordId使用:recordId 访问pl/sql块内部但是有没有办法recordId在不在pl/sql块中的sql语句中访问?(就像在最后一行).
我试图在java中构建一个动态的SQL查询(如下所示)
sqlStr = "Select * " +
"from " + tableName
if(tableName!=null){
if(tableName.equals("Table1"){
sqlStr = sqlStr.concat("order by city desc");
}else if(tableName.equals("Table2"){
sqlStr = sqlStr.concat("order by country desc");
}else if(tableName.equals("Table3"){
sqlStr = sqlStr.concat("order by price desc");
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想要做的是添加一个最终的'else'语句,该语句将根据表中是否包含名为'custID'的列来对查询进行排序.将有几个表与该列,所以我想按custID排序那些列.(而不是为每个具有该列名的表提供数百个额外的if语句.)这可能吗?我见过人们使用'解码'功能,但我不知道如何在这里使用它.