我正在尝试使用该toString(int[])方法,但我认为我做错了:
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Arrays.html#toString(INT [])
我的代码:
int[] array = new int[lnr.getLineNumber() + 1];
int i = 0;
System.out.println(array.toString());
Run Code Online (Sandbox Code Playgroud)
输出是:
[I@23fc4bec
Run Code Online (Sandbox Code Playgroud)
我也尝试过像这样打印,但是:
System.out.println(new String().toString(array)); // **error on next line**
The method toString() in the type String is not applicable for the arguments (int[])
Run Code Online (Sandbox Code Playgroud)
我从更大更复杂的代码中获取了这些代码,但是如果需要我可以添加它.但这应该提供一般信息.
我正在寻找输出,就像在Oracle的文档中一样:
字符串表示由数组元素的列表组成,用方括号括起来("[]").相邻元素由字符","(逗号后跟空格)分隔.
我想做这样的事情
switch (this.dealer) {
case 1-4:
// Do something.
break;
case 5-8:
// Do something.
break;
case 9-11:
// Do something.
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
这个的正确语法是什么?在JavaScript中可以吗?
那么this.dealer是一个整数,如果它在这些值之间,那么就做一些事情.
这是我的javascript:
function getWeather() {
$.getJSON('getTemperature/' + $('.data option:selected').val(), null, function(data) {
alert('Success');
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@RequestMapping(value="/getTemperature/{id}", headers="Accept=*/*", method = RequestMethod.GET)
@ResponseBody
public Weather getTemparature(@PathVariable("id") Integer id){
Weather weather = weatherService.getCurrentWeather(id);
return weather;
}
Run Code Online (Sandbox Code Playgroud)
为spring-servlet.xml
<context:annotation-config />
<tx:annotation-driven />
Run Code Online (Sandbox Code Playgroud)
得到此错误:
GET http://localhost:8080/web/getTemperature/2 406 (Not Acceptable)
Run Code Online (Sandbox Code Playgroud)
头:
响应标题
Server Apache-Coyote/1.1
Content-Type text/html;charset=utf-8
Content-Length 1070
Date Sun, 18 Sep 2011 17:00:35 GMT
Run Code Online (Sandbox Code Playgroud)
请求标题
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, …Run Code Online (Sandbox Code Playgroud) 与朋友一起开发应用程序,但遇到了一个问题...我有这个代码:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Run Code Online (Sandbox Code Playgroud)
他删除了所有内容,将其更改为:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
他说,这是更好的方法,但并没有完全解释原因.关于不直接使用hibernate的事情,这是否意味着我们不再使用hibernate了?它真的更好吗?
DAO改变如下:
我有:
@Autowired
private SessionFactory sessionFactory;
public void addUser(User user) {
sessionFactory.getCurrentSession().save(user);
}
Run Code Online (Sandbox Code Playgroud)
现在是:
@PersistenceContext
private EntityManager entityManager;
public void addUser(User …Run Code Online (Sandbox Code Playgroud) 我想更改端点地址,但它给我定义的值,我的意思是,只有一个值 "/".我试着在那里写,但它不起作用 - 它是不可编辑的.
我该怎么改变它?

我想单击一下取消选择所有值而不id单独使用每个值.
我摆弄了一会儿,但这只取消了第一个值.有什么建议?
这是我尝试取消选择的方式:
$( "#mybutton" ).click(function() {
$("select").select2('val', '')
});
Run Code Online (Sandbox Code Playgroud)
在将war文件部署到tomcat时出错:
log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,throwableRenderer?,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)"
Run Code Online (Sandbox Code Playgroud)
我google了一下,发现我的log4j.xml的排序可能是错误的,但它应该是正确的.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d %c %x - %m%n"/>
</layout>
</appender>
<root>
<priority value ="error" />
<appender-ref ref="console" />
</root>
<category name="org.springframework" additivity="false">
<priority value="info" />
<appender-ref ref="console" />
</category>
</log4j:configuration>
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我有超级Foo.还有一个扩展它的类Bar.
public class Bar extends Foo
Run Code Online (Sandbox Code Playgroud)
Foo中的功能:
protected void saveAll(Collection<?> many)
Run Code Online (Sandbox Code Playgroud)
栏中的功能:
public void saveAll(Collection<MyClass> stuff) {
super.saveAll(stuff);
}
Run Code Online (Sandbox Code Playgroud)
得到错误:
Name clash: The method saveAll(Collection<MyClass>) of type Bar has the same erasure as saveAll(Collection<?>) of type Foo but does not override it.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
Run Code Online (Sandbox Code Playgroud)
现在检查一下:
如果插入value1 = null,则将其更改为0
如何通过触发器来做到这一点?我用谷歌搜索了一些例子,我从来没有做过触发器,所以它相当令人困惑.
到目前为止只有这个:
CREATE TRIGGER testTrigger
ON myTable
AFTER INSERT, UPDATE, DELETE
Run Code Online (Sandbox Code Playgroud) return sessionFactory.getCurrentSession().
createQuery("FROM Weather WHERE city_id = :id AND date " +
"BETWEEN now()::date AND now()::date + (:days - 1)").
setInteger("id", city_id).setString("days", days).list();
Run Code Online (Sandbox Code Playgroud)
得到错误:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: :
Run Code Online (Sandbox Code Playgroud)
如何在HQL中使用此语法?
基本上问题是我想在我的查询中使用冒号(:),但是当hibernate看到冒号时,它认为它是一个参数(:parameterName是HQL中参数的语法),正如你从我的2个用途中看到的那样(:id and :days).
但是当我使用now():: date语句时,它是特定的postgreSQL语法,hibernate破坏了一切.