BBS > spring

jsonview xml

작성자 : 이창우 (x1wins) | 등록일 : 2012-04-29 | 목록
첨부 파일이 없습니다.
첨부 이미지가 없습니다.
	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
		p:order="1">
		<property name="mediaTypes">
			<map>
				<entry key="xml" value="application/xml" />
				<entry key="json" value="application/json" />
				<entry key="htm" value="text/html" />
			</map>
		</property>
		<property name="viewResolvers">
			<list>
				<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
				<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
					<property name="viewClass"
						value="org.springframework.web.servlet.view.tiles2.TilesView" />
				</bean>
				<bean
					class="org.springframework.web.servlet.view.InternalResourceViewResolver">
					<property name="prefix" value="/WEB-INF/views/" />
					<property name="suffix" value=".jsp" />
				</bean>
			</list>
		</property>
	</bean>

	<!-- tiles2 layout config -->
	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
		<property name="definitions">
			<list>
				<value>classpath:/tiles2/tiles*.xml</value>
			</list>
		</property>
	</bean>

	<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"
		p:order="0" />
	<bean id="jsonView" class="net.sf.json.spring.web.servlet.view.JsonView" />
	<bean id="xmlView"
		class="org.springframework.web.servlet.view.xml.MarshallingView">
		<property name="marshaller">
			<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
				<property name="autodetectAnnotations" value="true" />
				<property name="aliases">
					 <map>
					 	<entry  key="gw"  value="net.changwoo.gw.common.domain.Gw"/>
					 	<entry  key="bbs"  value="net.changwoo.gw.bbs.domain.Bbs"/>
						<entry  key="info"  value="net.changwoo.gw.bbs.domain.Info"/>
						<entry  key="famousSaying"  value="net.changwoo.gw.domain.FamousSaying"/>
						<entry  key="inventory" value="net.changwoo.gw.inventory.domain.Inventory"/>
						<entry  key="inout"  value="net.changwoo.gw.inventory.domain.InOut"/>
					 </map>
<!-- 					<props> -->
<!-- 						<prop key="bbs">net.changwoo.gw.bbs.domain.Bbs</prop> -->
<!-- 						<prop key="info">net.changwoo.gw.bbs.domain.Info</prop> -->
<!-- 						<prop key="famousSaying">net.changwoo.gw.domain.FamousSaying</prop> -->
<!-- 						<prop key="inventory">net.changwoo.gw.inventory.domain.Inventory</prop> -->
<!-- 						<prop key="inout">net.changwoo.gw.inventory.domain.InOut</prop> -->
<!-- 					</props> -->
				</property>
			</bean>
		</property>
		<!-- <property name="replacer"> -->
		<!-- <bean class="net.changwoo.util.Replacer"/> -->
		<!-- </property> -->
	</bean>
spring config
<dependency>
			<groupId>net.sf.json-lib</groupId>
			<artifactId>json-lib-ext-spring</artifactId>
			<version>1.0.2</version>
		</dependency>
		<dependency>
			<groupId>com.thoughtworks.xstream</groupId>
			<artifactId>xstream</artifactId>
			<version>1.4.1</version>
		</dependency>
pom.xml
	@RequestMapping(value = "/detail/{num}/{protocol}", method = RequestMethod.GET)
	public String doDetail(Model model, @PathVariable String num,
			@PathVariable String protocol) {

		try {

			Bbs bbs = bbsService.getBbsDetail(num);
			model.addAttribute("bbs", bbs);

		} catch (Exception e) {
			e.printStackTrace();
		}

		return protocol + "View";
	}
controller
if you want json or xml rest response
put json or xml in path parameter

this exsample show common rest response
i use one controller but i can double type result json or xml
로그인 하셔야 댓글을 사용하실수 있습니다.
댓글쓰기를 누르면 로그인 페이지로 이동 후 돌아옵니다.
총 댓글 겟수 1
이창우(x1wins) | 2012-09-13
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
번호 제목 등록일 작성자 조회수
634 하이버네이트 no session (0) 2013-08-04 이창우 1416
631 hibernate join example (0) 2013-07-05 이창우 1462
630 hibernate 추론성 제거 (0) 2013-07-03 이창우 1343
629 http 406 에러 (0) 2013-07-02 이창우 4092
628 spring 3.2 에러 (0) 2013-07-02 이창우 1190
626 spring long-polling chat (0) 2013-06-25 이창우 7851
621 hibernate order (0) 2013-05-03 이창우 1402
593 자주 쓰게 될 pom? (0) 2012-11-29 이창우 1329
592 spring data (0) 2012-11-29 이창우 1327
566 hibernate 1:n duplicates (0) 2012-08-22 이창우 1658
565 hibernate no session (1) 2012-08-08 이창우 1678
562 maven tool.jar (0) 2012-08-02 이창우 1833
561 hibernate 정보 모음 (0) 2012-08-01 이창우 2435
556 메이븐 프로젝트 웹프로젝트로 시작하기 (0) 2012-07-17 이창우 1639
555 @ResponseBody sample (0) 2012-07-15 이창우 2618
549 comet with spring (0) 2012-07-05 이창우 1783
529 hinbernate Criteria join (4) 2012-05-07 이창우 2310
525 properties 이클립스 한글 (0) 2012-04-29 이창우 2028
-> jsonview xml (1) 2012-04-29 이창우 2845
523 error (0) 2012-04-25 이창우 1709
< 1 2 3 >
글쓰기 검색