spring mvc+spring+mybatis+json統合


暇な時は大丈夫です.新しいspring mvc 3.2を勉強しました.前のバージョンより使いやすいと思います.
ちなみにmybatisと統合しました.
学生選択のデモを書きました.
主な実現点:
1.mybatis-3.2.2はspring 3.2.0と整合しています.統合する時はappication Contact.xmlにmybatisのいくつかの情報を配してください.
   キーコード:
  appication Contect.xml
	<context:property-placeholder location="classpath:jdbc.properties"/>
	<bean id="dataSource" class="org.apache.ibatis.datasource.pooled.PooledDataSource" destroy-method="forceCloseAll">
		<property name="driver" value="${jdbc.driver}"/>
		<property name="url" value="${jdbc.url}"/>
		<property name="username" value="${jdbc.username}"/>
		<property name="password" value="${jdbc.password}"/>
	</bean>
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>
	<tx:annotation-driven/>
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<property name="typeAliasesPackage" value="com.jayung.curriculum.domain"/>
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.jayung.curriculum.mapper"/>
	</bean>
 springでmybatis事務を管理して、DAOの実現類を書く必要がなくて、コードはとても簡潔で、service階は直接mybatisのmapper種類(DAOインターフェースに相当します)を呼び出して、添削して操作して、serviceの対応する方法の上で@Transactionをプラスします.
 
	@Transactional
	public void save(Student student) {
		studentMapper.insert(student);
	}
 
 
2.スプリングmvc
   全面的に注釈を使用して、非常に簡潔で、符号化する時、xmlとjavaコードを往復で切り替える必要がなくて、一つ@Controllerと@Request Mappingは大量のxml配置に取って代わって、感じはとても良いです.
   二つのブロックを書きました.学生が登録するかどうか、ブロック管理者が登録するかどうか、Filterの代わりにスプリングスクリーンを使って登録するかどうかを検査します.Request MappingブロッキングはFilterより有効です.例外ブロックリストを配置することもできます.
 
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/student/**"/>
			<mvc:mapping path="/courses"/>
			<bean class="com.jayung.curriculum.web.interceptor.LoginInterceptor"/>
		</mvc:interceptor>
		<mvc:interceptor>
			<mvc:mapping path="/console/**"/>
			<bean class="com.jayung.curriculum.web.interceptor.ConsoleInterceptor">
				<property name="excludeURIs">
					<list>
						<value>/console</value>
						<value>/console/login</value>
					</list>
				</property>
			</bean>
		</mvc:interceptor>
	</mvc:interceptors>
 
 
3.レストfulのurl
   iteyeに似たurlを実現します.  http://www.iteye.com/news/28054
 例えば、http://localhost:8080/curriculum/student/1234は、学号が1234の学生情報を表示し、http://localhost:8080/curriculum/student/1234/coursesは、学号が1234の選択科目であることを表示し、
http://localhost:8080/curriculum/console/student/1122/edit,学号1122学生の情報を編集します.
以前はこのようなurlを実現するために、UrlRewriteFilterを利用して、現在はspring mvcでこのようなurlを原生的に実現できますが、現在はブラウザはpostとgetの両方の提出方式しかサポートしていませんので、restはすべて実現しています.
	@RequestMapping("/student/{studentId}")
	public String view(@PathVariable String studentId, Model model) {
		model.addAttribute("student", studentService.view(studentId));
		return "/student/view";
	}
 
添付ファイルのDemoには以下の内容が含まれています.
spring、spring mvc、mybatis、spring登録スクリーン、springタイミングタスクの実際の方式、ajaxはjsonフォーマットデータなどを転送します.
 
添付ファイルを再整理しました.アップロードしました.必要な学生の参考に供します.