我在两个其他表之间使用Hibernate 4和一个简单的"连接表".以下是JPA 1.0兼容实体:
@Entity
@Table(name = "Companies")
public class Company
{
@Id
@Column
private Integer id;
@Column
private String name;
...
}
Run Code Online (Sandbox Code Playgroud)
和
@Entity
@Table(name = "PQs")
public class PQ implements Serializable
{
@Id
@Column
private Integer id;
@Column
private String name;
...
}
Run Code Online (Sandbox Code Playgroud)
正如您可以看到两个类似的表,只是一个简单的ID加名称.现在互连实体:
@Entity
@Table(name = "Partnerships")
@IdClass(value = PartnershipId.class)
public class Partnership implements Serializable
{
@Id
@Column(name = "pq_id", insertable = false, updatable = false)
private Integer pqId;
@Id
@Column(name = "company_id", insertable = false, updatable = …Run Code Online (Sandbox Code Playgroud) 我不知道这是否也困扰你.Emacs出于某种原因使用这些组合键.他们中的一些人很疯狂.你想要撤消一些东西,猜猜是什么!ctrl + shift + dash!同时有3个按键,有时它们不会同时按下,你必须重复它.在这个漫长的过程中,你会在屏幕上输入一些不需要的字符,并且必须在后面删除它们......或者ctrl + shift + <.在vim中撤消只是"你"!
我厌倦了这些组合.但我喜欢emacs的其他功能,不想转向vim.你们怎么处理这个问题?你有没有映射键,或习惯了emacs和弦键?
重新调用emacs本机密钥我认为由于各种原因不是一个好主意.不确定有多少人真正这样做.
快问.当你在webApp使用的另一个jar中时,你可以在applicationContext.xml中引用Spring类吗?
JAR(包含我所有服务和daos等的常见jar)在WAR文件中,但是当我尝试通过applicationContext.xml引用服务时,我收到以下错误: -
Error creating bean with name 'com.myproject.common.test.impl.TestServiceImpl' defined in ServletContext resource [/WEB-INF/context/spring-context.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
Run Code Online (Sandbox Code Playgroud)
(注意spring-context.xml被导入applicationContext.xml而没有错误.)
我的上下文XML:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="com.myproject.common.test.impl.TestServiceImpl">
<property name="genericDao" ref="genericDao" />
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
我的应用程序包都在com.myproject.web下我的常见JARS都在com.myproect.common下
将JSON转换为XML并返回的最佳方法是什么?例如,下面的JSON
{
"user": "gerry",
"likes": [1, 2, 4],
"followers": [
{
"name": "megan"
},
{
"name": "pupkin"
}
]
}
Run Code Online (Sandbox Code Playgroud)
可以像这样转换成XML(#1):
<?xml version="1.0" encoding="UTF-8" ?>
<user>gerry</user>
<likes>1</likes>
<likes>2</likes>
<likes>4</likes>
<followers>
<name>megan</name>
</followers>
<followers>
<name>pupkin</name>
</followers>
Run Code Online (Sandbox Code Playgroud)
或者像这样(#2):
<?xml version="1.0" encoding="UTF-8"?>
<root>
<likes>
<element>1</element>
<element>2</element>
<element>4</element>
</likes>
<followers>
<element>
<name>megan</name>
</element>
<element>
<name>pupkin</name>
</element>
</followers>
<user>gerry</user>
</root>
Run Code Online (Sandbox Code Playgroud)
特别是,转换阵列会产生差异.对象属性转换非常简单.我也确定还有其他方法可以将JSON转换为XML.
所以问题是:最好的方法是什么?有标准吗?
另一个问题是:有没有办法以某种数学形式表达转换映射本身.例如,是否可以描述映射,以便在给定JSON对象和映射对象时转换函数将准确知道要生成哪个XML.并且反过来.
XML_1 = convert(JSON, mapping_1)
XML_2 = convert(JSON, mapping_2)
JSON = convert(XML_1, mapping_1)
JSON = convert(XML_2, mapping_2)
JSON = convert(XML_1, mapping_2) # Error!
Run Code Online (Sandbox Code Playgroud) 我试图了解Orika何时使用转换器进行映射而不是直接转换。
我有以下映射:
Class A {
Map<String, Object> props;
}
Class B {
String bStr;
int bInt;
}
Run Code Online (Sandbox Code Playgroud)
我的映射定义为props ['aStr'] => bStr和props ['aInt'] => bInt
当查看生成的代码时,我发现对于String情况,它使用一个转换器并调用其convert方法进行转换:
destination.setBStr("" + ((ma.glasnost.orika.Converter)usedConverters[0]).convert(
((java.lang.Object) ((java.util.Map) source.getProps().get("aStr"),
(ma.glasnost.orika.metadata.Type) usedTypes[0]))
Run Code Online (Sandbox Code Playgroud)
但是,对于整数情况,它将直接像这样进行转换:
destination.setBInt((java.lang.Integer)(java.lang.Object) ((java.util.Map)
source.getProps().get("aInt")))
Run Code Online (Sandbox Code Playgroud)
上面的代码行最终给了类强制转换异常。
为了解决此问题,我一直在考虑使用自定义转换器,但是如果上面的代码行不使用转换器,那将无法正常工作。
当然,我总是可以在我的自定义映射器中执行此操作,但是只是试图了解如何为类型转换生成代码。
谢谢!!
constructor(props) {
super(props);
let comments = [{body: "good", created_at:"2018-02-12T05:27:47.175Z"},
{body: "bad article", created_at:"2017-11-12T05:27:47.175Z"},
{body: "great", created_at:"2017-10-12T05:27:47.175Z"}];
this.state = { comments };
render() {
return(
{ comments.map((comment, index) =>
<Text>{comment.body}</Text>
)}
);
};
Run Code Online (Sandbox Code Playgroud)
数据按降序排列,但我想根据created_at日期按升序排序.
现在,新的评论首先出现,并且想要先老的评语.
我该如何对此评论进行排序?请建议任何解决方案.
我开始在日常编码中使用vim.在我探索的过程中,我发现了使用*map.所以我决定将以下映射添加到我的.vimrc文件中.
inoremap ' ''<left>
inoremap " ""<left>
imap ( ()<left>
imap { {}<left>
imap [ []<left>
imap < <><left>
Run Code Online (Sandbox Code Playgroud)
我的想法是匹配每个',',(,{,[,<与其结束等效.这个问题是,即使我在插入模式下粘贴,映射仍然有效.
// Pasting this
()=>{ console.log("Hello World"); }
//Will result to something like this
())=>{} console.log())""Hello World"");}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能防止这种情况发生?
我一直致力于普通lisp的jarvis march实现.jarvis march算法采用一堆点并返回该点云的凸包.我将每个点表示为这样的结构:
(defstruct point x y)
Run Code Online (Sandbox Code Playgroud)
然后我继续定义一个测试集,但是,由于初始化结构的符号相当长(make-point :x 0 :y 1),我决定创建一个自动为我做的函数:
(defun make-points (list)
(map
'list
(lambda (e) (make-point :x (first e) :y (second e)))
list))
Run Code Online (Sandbox Code Playgroud)
可悲的是,它不起作用.
(print (first (make-points '('(2 3))))) ;prints out '#S(POINT :X QUOTE :Y (2 3))' => wrong
(print (make-point :x 2 :y 3)) ;prints out '#S(POINT :X 2 :Y 3)' => correct
Run Code Online (Sandbox Code Playgroud)
它将完整列表(2 3)绑定到所有事物的y值,并且它不为x值赋值.为什么会这样做以及如何解决它.
在此先感谢,我对lisp相当新鲜(正如你可能从这个问题中猜到的那样),如果有人可以帮助我,我将非常感激.如果有人知道任何捷径或对我的工作方法有任何好的论据也会很好,虽然在评论中告诉我他们可能会更好,因为他们不会直接回答这个问题.
尝试使用嵌套在子对象结构中的值来映射对象数组:
const objs = [{
"B": {
"value": 1,
},
"D": {
"value": "45"
},
"E": {
"value": "234"
},
"A": {
"value": "543"
},
"C": {
"value": "250"
}
},...]
Run Code Online (Sandbox Code Playgroud)
结构如下:
[
{ name: 'B', value: 1 },
{ name: 'D', value: '45' },
{ name: 'E', value: '234' },
{ name: 'A', value: '543' },
{ name: 'C', value: '250' }
]
Run Code Online (Sandbox Code Playgroud)
映射的结果是 undefined
const mapped = objs.map((key, index) => {
Object.keys(key).map(el => ({
name: el
}))
}) …Run Code Online (Sandbox Code Playgroud) 我正在映射一个称为Tours的数组
export const tourData = [
{
id: 1,
city: "new york",
img: "./img/newyork.jpeg",
name: "new york bridge tour",
info:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel,repellendus!"
},
Run Code Online (Sandbox Code Playgroud)
如下所示
state={
tours: tourData
}
render(){
const {tours} = this.state;
return(
<section className="tourlist">
{tours.map(tour => {
return (
<Tour key={tour.id} tour={tour} removeTour={this.removeTour}/>
)
})}
</section>
)
}
Run Code Online (Sandbox Code Playgroud)
我将巡回演出作为道具传递给巡回演出组件。
const {id , city , img, name, info} = this.props.tour;
const {removeTour} = this.props;
Run Code Online (Sandbox Code Playgroud)
该webapp运行良好,但是当我对Tour组件进行测试并且我将值作为prop传递时
const props ={
id : 1,
city: …Run Code Online (Sandbox Code Playgroud) mapping ×10
arrays ×2
java ×2
javascript ×2
reactjs ×2
chord ×1
combinations ×1
common-lisp ×1
emacs ×1
hibernate ×1
jpa ×1
json ×1
key ×1
orika ×1
react-native ×1
readonly ×1
sorting ×1
spring ×1
typescript ×1
vim ×1
xml ×1