我花了一些时间寻找最好的方法来逃避html字符串并找到一些讨论:讨论1 讨论2.它引导我替换所有功能.然后我做了性能测试,并试图找到实现类似速度的解决方案,但没有成功:(
这是我的最终测试用例集.我在网上找到它并随着我的尝试扩展(底部有4个案例)但仍无法达到replaceAll()
性能.
什么是秘密女巫使replaceAll()
解决方案如此迅速?
映入眼帘!
代码片段:
String.prototype.replaceAll = function(str1, str2, ignore)
{
return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
};
Run Code Online (Sandbox Code Playgroud)
qwerty的学分
迄今为止最快的案例:
html.replaceAll('&', '&').replaceAll('"', '"').replaceAll("'", ''').replaceAll('<', '<').replaceAll('>', '>');
Run Code Online (Sandbox Code Playgroud) 我怎样才能字段名引起org.hibernate.exception.ConstraintViolationException
?检查唯一约束的唯一可靠方法是事务提交,因此即使我在抛出异常之前检查它也是如此.所以,我需要传达给用户的女巫场引起保存问题.
详细消息或多或少是技术性的,用户不能接受.它还取决于数据库驱动程序:( IMO 字段名称就足够了,我可以从对象中获取有问题的值.还可以准备其他信息......但字段名称.
我将使用 Netflix Zuul 实现 API 网关。是否可以设置任何规则来防止:
我发现只有外部解决方案(API 网关)支持它:(
我在这里阅读了 Spring Data Binder 的全面解释:/sf/answers/259409881/
我的问题需要更多的知识,让我强调一下:
我有具有复杂字段的 Person 对象 - 例如与街道和数字字段的联系。所以我们可以这样描述:
public class Contact {
private String street;
private int number;
// setters & getters
};
public class Person {
private String name;
private int age;
private Contact contact;
// setters & getters
};
Run Code Online (Sandbox Code Playgroud)
我认识到 spring 将其表示为 html 表单,如下输入字段:
姓名、年龄、contact.street、contact.number
我认为,当它返回时,它可以将它放回 Person 对象。
我想“雇用”Spring Binder 来为我提供的文本数据创建对象(不是 HttpRequest 对象)。例如我有文件:
name age street number
John 22 MHDrive 2187
Will 32 MHDrive 3212
Run Code Online (Sandbox Code Playgroud)
我可以提供上面的任何结构并想要获取 Person 对象:)
例如
Person p = springBinderSomething({{"name","John"},{"age","22"},{"street","MHDrive"},{"number","2187"}}, Person.class); …
Run Code Online (Sandbox Code Playgroud) 我有循环来保存几个对象.在循环中调用服务方法并捕获异常.服务保存方法注释@Transactional,内部执行hibernate saveOrUpdate调用.服务由ApplicationContext对象的getBean方法提供.我在循环前只调用一次.
在循环中,在我捕获oracle约束违规的异常之后:
org.hibernate.exception.constraintviolationexception:ora-00001:违反了唯一约束(ccb.sys_c0017085)
我记录问题并尝试保存另一个对象.我得到的下一个例外是:
org.hibernate.HibernateException:代理句柄不再有效
有时它在每次ora错误后只发生一次,但有时它会重复更多的对象(迭代).
如何处理此异常以及如何使保存操作成为可能?
我正在使用Spring 3.1.3和Hibernate 4.1.7.
[编辑]一些代码示例:
@Service
public class ServiceForRecord {
@Transactional
public Record saveRecord(Record record, String user) {
Record obj = record;
// some validation & seting internal values
getHibernateTemplate().saveOrUpdate(obj)
return obj;
}
...
Run Code Online (Sandbox Code Playgroud)
在我的循环中,我做:
//in params:
serviceClass = ServiceForRecord.class;
entityClass = Record.class;
saveMethod = "saveRecord";
//loop prepare
service = getApplicationContext().getBean(serviceClass);
serviceSave = serviceClass.getMethod("saveRecord", Record.class, String.class);
while (condition) {
entity = BeanUtils.instantiate(entityClass);
//setup entity
serviceSave.invoke(service, entity, "testUser");
//catch error
} //end while
Run Code Online (Sandbox Code Playgroud)
[编辑]堆栈跟踪: …
我尝试使用css进行构建页面布局.我希望它尽可能多地独立于内容.
我的想法是每行有4个div,我使用float:left为所有div和:nth-child(4n + 1)选择器为clear:both.有些div我想成为第一个(cr之前),并且我用class ="cr"标记它,但是我希望它在同一行之后有3个div,在cr之前(clear:both).
目标是:
Test Test
Test Test Test Test
Test Test Test Test
Run Code Online (Sandbox Code Playgroud)
可能吗 ?到目前为止我在这里:http: //jsbin.com/isowab/1/edit
spring ×3
css ×2
hibernate ×2
java ×2
css3 ×1
html ×1
javascript ×1
performance ×1
spring-cloud ×1
spring-mvc ×1