我的控制器中有一个简单的处理程序,它返回一条消息
@RequestMapping(value = "/message")
@ResponseBody
public Message get() {
return new Message(penguinCounter.incrementAndGet() + " penguin!");
}
Run Code Online (Sandbox Code Playgroud)
同时我可以使用这样的东西
@RequestMapping(value = "/message")
ResponseEntity<Message> get() {
Message message = new Message(penguinCounter.incrementAndGet() + " penguin!");
return new ResponseEntity<Message>(message, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
这两种方法有什么区别?我们不考虑HttpStatus :)
我wait()在课堂上找到了这个方法Object.
这是最终的,这意味着不能覆盖此方法.
任何想法为什么它是最终的?
我想将H2内存数据库添加到我的Spring MVC应用程序中。对于ORM,我正在使用Hibernate。这是我的配置:
[hibernate.cfg.xml]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:~/myDB</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">qwerty</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="de.alf.h2.entity.Student"/>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
[data.xml]
<bean:beans xmlns:bean="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ctx="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<ctx:component-scan base-package="de.alf.h2.repository"/>
<bean:bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate">
<bean:property name="sessionFactory" ref="sessionFactory"/>
</bean:bean>
<bean:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<bean:property name="configLocation" value="classpath:/hibernate/hibernate.cfg.xml"/>
</bean:bean>
<bean:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<bean:property name="sessionFactory" ref="sessionFactory"/>
</bean:bean>
</bean:beans>
Run Code Online (Sandbox Code Playgroud)
[web.xml]
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet> …Run Code Online (Sandbox Code Playgroud)