[英]Search in my WEB-application works only with latin symbols when I deploy it on openshift, but it works fine on my local machine
I have a problem. 我有个问题。 I made a WAB-application by Spring MVC & Hibernate and it has a search.
我通过Spring MVC和Hibernate制作了WAB应用程序,并且进行了搜索。 Problem is the search works only with latin symbols when I deploy the WEB-application on openshift.
问题是,当我在openshift上部署WEB应用程序时,搜索仅适用于拉丁文符号。 It doesn't work with cyrillic.
西里尔字母不适。 But it works very well on my local machine.
但是它在我的本地计算机上运行得很好。 So I have no idea what it can be.
所以我不知道这可能是什么。 I have the same database on openshift that on my local machine and I did a dump of my data and imported it to openshift.
我在openshift上有与本地计算机上相同的数据库,我转储了数据并将其导入到openshift中。
This is the method of search: 这是搜索方法:
public List<News> getNewsWithSubstring(String str) {
Session session = sessionFactory.getCurrentSession();
Criteria crt = session.createCriteria(News.class);
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.like("titleUa", "%" + str + "%"));
disjunction.add(Restrictions.like("titleEn", "%" + str + "%"));
disjunction.add(Restrictions.like("titleRu", "%" + str + "%"));
disjunction.add(Restrictions.like("descriptionUa", "%" + str + "%"));
disjunction.add(Restrictions.like("descriptionEn", "%" + str + "%"));
disjunction.add(Restrictions.like("descriptionRu", "%" + str + "%"));
crt.add(disjunction);
return crt.list();
}
This is the settings of connect to db (from springServlet-context.xml): 这是连接到数据库的设置(来自springServlet-context.xml):
<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.goldcamtech.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="c3p0.idle_test_period">120</prop>
<prop key="hibernate.connection.characterEncoding">utf8</prop>
</props>
</property>
</bean>
<bean name="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.18.97.4:3306/gctech_site?autoReconnect=true&useUnicode=true&characterEncoding=utf-8"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
Maybe someone has any idea? 也许有人有什么主意? Why does it work with latin and cyrillic on my local machine but doesn't work with cyrillic on openshift?
为什么在我的本地计算机上不能使用拉丁文和西里尔文,但在openshift上不能与西里尔文一起使用? Thanks!
谢谢!
Most likely the problem lies in default configuration of MySQL on your local machine and MySQL at OpenShift. 问题很可能出在本地计算机上的MySQL的默认配置以及OpenShift上的MySQL的默认配置。 I suggest to compare the
CHARACTER SET
on the tables/database. 我建议比较表/数据库上的
CHARACTER SET
。 If you didn't specify it explicitly when creating tables/database MySQL will use default value from my.cnf
如果在创建表/数据库时未明确指定,则MySQL将使用
my.cnf
默认值
See also: Database Character Set and Collation 另请参阅: 数据库字符集和排序规则
PS Also be warned, that code like this PS也请注意,这样的代码
disjunction.add(Restrictions.like("titleUa", "%" + str + "%"));
may work wrong in some situations (for instance, if user's string contains %
or _
characters) and even more, it may cause SQL injection. 在某些情况下(例如,如果用户的字符串包含
%
或_
字符)可能会出错,甚至更多,这可能会导致SQL注入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.