我试图构建我的第一个支持i18n的Spring MVC 4应用程序,并且正在思考如何在用户将语言uri参数操作到非现有或支持的语言环境时如何使用默认/回退语言环境例如 http:// localhost .DE?LANG = ABC
我正在使用代码
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setDefaultLocale(Locale.GERMAN);
return sessionLocaleResolver;
}
Run Code Online (Sandbox Code Playgroud)
一般情况下,如果我第一次打开网址,但它似乎不适用于我描述的情况.我知道有一种机制可以使用默认的消息属性文件,但我想为这种情况设置一个默认/回退区域设置.我是否需要实现自定义过滤器?
我试图激活我的Apache HttpClient的调试日志记录,但无法使其工作(没有得到任何与HttpClient相关的日志记录输出).
这是我目前使用的log4j2配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile name="RollingRandomAccessFile" fileName="logs/test.log" filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>
%d %p %c{1.} [%t] %m%n
</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
<Async name="async">
<AppenderRef ref="RollingRandomAccessFile" />
</Async>
</appenders>
<loggers>
<logger name="org.apache.http.wire" level="debug" />
<logger name="org.apache.http.client" level="debug" />
<logger name="org.apache.xerces.parsers.SAXParser" level="warn" />
<logger name="org.hibernate" level="warn" />
<root level="trace">
<appender-ref ref="console" />
<appender-ref ref="async" />
</root>
</loggers> …Run Code Online (Sandbox Code Playgroud) 我使用SpringSecurity 2.0-RC2并希望用户在联机时提供更改密码的可能性.
我的用户域类具有以下内容
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
Run Code Online (Sandbox Code Playgroud)
要检查用户是否正在输入正确的当前密码,我在控制器中执行以下操作:
if (springSecurityService.encodePassword(params.currentPassword) == user.password) {
Run Code Online (Sandbox Code Playgroud)
...但是(对我而言)支票总是失败.即使我这样做也更奇怪:
println springSecurityService.encodePassword(params.currentPassword)
println springSecurityService.encodePassword(params.currentPassword)
Run Code Online (Sandbox Code Playgroud)
我在控制台中收到以下内容
$ 2A $ 10 $ $ sWt7mUSHPFT.Np6m.gXyl.h8tWqblJbwtzQ6EQeMHxXMoGwOffC3e 2A $ 10 $ lwHz1SkNlW8ibznt.mOiruAg5eG/BTtsjM7ChyYVBvamRcrL8tucm
(就像会有盐 - 但我自己没有配置)
我的设置或多或少是默认设置; 除了三个域类的包名称.
由于文件很严重,因为我在这里问到是否有人知道我做错了什么......
我需要设计一些数据库表,但我不确定性能影响.在我的情况下,它更多地关于读取性能而不是保存数据.
情况
借助模式识别,我可以找到需要在postgresql数据库中保存多少某个对象的值.其他数量让我们说固定属性唯一的区别是需要保存相同类型的1,2或3个值.
目前,我有3个实体/表,它们的区别仅在于具有相同类型的1,2或3个不可空的属性.
例如:
EntityTestOne/TableOne {
... other (same) properties
String optionOne;
}
EntityTestTwo/TableTwo {
... other (same) properties
String optionOne;
String optionTwo;
}
EntityTestThree/TableThree {
... other (same) properties
String optionOne;
String optionTwo;
String optionThree;
}
Run Code Online (Sandbox Code Playgroud)
我希望生产中有数百万条记录,并且我正在考虑这种变体的性能影响以及可能的替代方案.
备择方案
我想到的其他选择:
例如:
EntityOption {
String value;
}
EntityTest {
... other (same) properties
List<EntityOption> options;
}
Run Code Online (Sandbox Code Playgroud)
由于我不是那么强大的数据库设计和使用hibernate我对这些方法的优缺点感兴趣,如果有更多的选择.我甚至想问一个问题,如果postgresql是正确的选择,或者是否应该考虑使用另一个(免费)数据库.
谢谢!
昨天我尝试将一些弹簧启动项目合并到一个新项目中,从那时起,我在启动项目时在ide控制台中遇到以下错误:
Ignoring Class-Path entry xercesImpl.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xalan-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xercesImpl.jar does not exist
Ignoring Class-Path entry xml-apis.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xalan-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xml-apis.jar does not exist
Ignoring Class-Path entry serializer.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xalan-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/serializer.jar does not exist
Ignoring Class-Path entry xml-apis.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/serializer/2.7.2/24247f3bb052ee068971393bdb83e04512bb1c3c/serializer-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/serializer/2.7.2/24247f3bb052ee068971393bdb83e04512bb1c3c/xml-apis.jar does not exist
Run Code Online (Sandbox Code Playgroud)
这些消息作为System.err消息打印.
检查路径会显示以下图片:
test@localhost ~/.gradle/caches/modules-2/files-2.1/xalan $ ls -lRt
.:
total 8
drwxr-xr-x 3 test test 4096 Jul 6 07:54 serializer
drwxr-xr-x 3 test test 4096 Jul 6 07:54 xalan
./serializer:
total 4
drwxr-xr-x 5 test test …Run Code Online (Sandbox Code Playgroud) 我试图将我们的构建过程从Maven改为Gradle(V 2.9).在Maven中我正在使用JSP的预编译:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jspc-maven-plugin</artifactId>
<version>9.2.7.v20150116</version>
<executions>
<execution>
<phase>package</phase>
<id>jspc</id>
<goals>
<goal>jspc</goal>
</goals>
<configuration>
<excludes>**\/*inc_page_bottom.jsp,**\/*inc_page_top.jsp</excludes>
<includes>**\/*.jsp</includes>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
它工作正常.现在我试图找到一种方法来做同样的gradle.我找到了一些信息/ build.gradle示例,但没有什么工作真的.我目前使用Tomcat 7作为servlet容器,我计划在几周内切换到8.当然,为目标servlet容器编译它们当然是完美的但首先我很乐意预编译它们就像我这样做与maven为/与码头.
我当前build.gradle的一部分,它给了我一个错误:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.4'
}
}
apply plugin: 'com.bmuschko.tomcat'
tomcat {
jasper {
validateXml = true
errorOnUseBeanInvalidClassAttribute = false
compilerSourceVM = "1.8"
compilerTargetVM = "1.8"
}
}
task compileJsps(type: JavaCompile, dependsOn: 'clean') {
dependsOn tomcatJasper
group = 'build'
description = 'Translates and compiles JSPs'
classpath = configurations.tomcat + sourceSets.main.output + …Run Code Online (Sandbox Code Playgroud) 我有一个这样的枚举:
public static enum TestEnum {
// main
ENUM_A (1, "test1", TestADto.class),
ENUM_B (2, "test2", TestBDto.class),
ENUM_C (3, "test3", TestCDto.class),
...
private Class<? extends Dto> dtoClass;
public Class<? extends Dto getDtoClass() {
return dtoClass;
}
...
}
Run Code Online (Sandbox Code Playgroud)
所有这些dto类都扩展了相同的抽象(dto)类:
public abstract class AbstractDto {
private String foo;
private int bar;
...
AbstractDto(AbstractClassNeededForInitialization o) {
this.foo = o.getFoo();
this.bar = o.getBar();
}
... some functions here ...
}
Run Code Online (Sandbox Code Playgroud)
这将是TestADto的示例Dto实现:
@Getter
@Setter
public class TestADto extends AbstractDto {
private String anotherFoo;
private int …Run Code Online (Sandbox Code Playgroud) 我们在我们的项目中使用 jquery,我们正在考虑实现一个功能,用于提供从我们的网站到本地底层文件系统(例如桌面...)的拖放下载。我找到了一些有用的链接,但所有这些似乎都过时了:
http://ankurm.com/html-5-dnd-download-a-quick-implementation/
http://www.html5rocks.com/en/tutorials/casestudies/box_dnd_download/
https://www.salesking.eu/blog/coding/jquery-plugin-to-drag-files-from-browser-onto-desktop/
我的问题:
有人知道支持此功能的浏览器及其版本的概述吗?我阅读了 HTML5 的一部分,但并非每个 HTML5 浏览器都支持此功能。更糟糕的是:在其中一个链接中,用户写道一些浏览器支持此功能,但过了一段时间后,该支持被删除了...
有没有人知道“现在”如何实施它的最新方法?
提前谢谢!
我试图建立一个spring(3.1)和hibernate(3.6.10)Web应用程序,并遇到hibernate事件的问题.我实现了自己的DefaultSaveOrUpdateEventListener来更新/创建在每个.saveOrUpdate()事件上调用的dateCreated和lastUpdated日期.到现在为止还挺好.
不应该在.save()或.update()事件上调用此侦听器吗?或者我错过了什么?
监听器:
public class SaveOrUpdateDateListener extends DefaultSaveOrUpdateEventListener {
private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(SaveOrUpdateDateListener.class);
@Override
public void onSaveOrUpdate(SaveOrUpdateEvent event) {
log.debug("Entered onSaveOrUpdate()");
if (event.getObject() instanceof BaseDomain) {
BaseDomain record = (BaseDomain) event.getObject();
record.setDateUpdated(new Date());
if (record.getDateCreated() == null) {
record.setDateCreated(new Date());
}
}
super.onSaveOrUpdate(event);
}
}
Run Code Online (Sandbox Code Playgroud)
Hibernate配置(部分):
<sesssion-factory>
<event type="save-update">
<listener class="net.test.listener.hibernate.SaveOrUpdateDateListener"/>
<listener class="org.hibernate.event.def.DefaultSaveOrUpdateEventListener"/>
</event>
</session-factory>
Run Code Online (Sandbox Code Playgroud)
示例dao方法(不起作用):
@Autowired
private SessionFactory sessionFactory;
@Override
public void add(Registration registration) {
sessionFactory.getCurrentSession().save(registration);
}
@Override …Run Code Online (Sandbox Code Playgroud) 目前我正在从事一个项目,我们最近对此进行了讨论。因此,让任何带有数字列的数据库表都允许在源代码中“无值”。
我的一些同事更喜欢在其映射对象中使用基本类型 int 并将本例中的值设置为 -1;我更喜欢使该列可为空,使用源中的 Integer 对象而不是原始类型,并将该值设置为 null。
现在我正在寻找两种变体的优点和缺点,但到目前为止找不到任何东西。
到目前为止我找到的唯一一篇文章是这篇: http://www.javapractices.com/topic/TopicAction.do?Id=134 ...
这条规则有一个非常常见的例外。对于粗略映射到数据库记录的模型对象,通常适合使用 null 来表示在数据库中存储为 NULL 的可选字段
...
@编辑我需要补充一点,这种列在这个项目中用作一种假外键。它们不是真正的数据库约束,但用作数据库约束。不要问我为什么...我知道我知道:-) -1 在这种情况下意味着它与另一个表的主键/id 没有关系。所以它不需要任何计算或类似的东西......
我正在研究基于Java的Web应用程序,突然发现了一种我目前无法理解的行为.
假设我有以下代码:
...snip...
Map<Integer, Foo> map = new HashMap<Integer, Foo>();
...snip...
public List<Foo> getFoos() {
return (List<Foo>)map.values();
}
Run Code Online (Sandbox Code Playgroud)
我知道你需要像新的ArrayList()那样实例化一个新的List,但我想知道为什么eclipse没有给我一个警告.
只有在运行代码时我才会获得ClassCastException.我很确定这不是eclipse的错误,因为编译器也没有这个代码的问题,但有人可以解释为什么你在运行这段代码时总是出错,但是IDE和编译器没有抱怨?
java ×5
gradle ×2
hibernate ×2
apache ×1
database ×1
download ×1
eclipse ×1
grails ×1
html ×1
java-8 ×1
javascript ×1
jdbc ×1
jquery ×1
jsp ×1
log4j2 ×1
logging ×1
persistence ×1
postgresql ×1
precompile ×1
spring ×1
spring-boot ×1
spring-mvc ×1
tomcat7 ×1