67,513
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>springjdbc</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.txt</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--<welcome-file-list>-->
<!--<welcome-file>/WEB-INF/page/prelogin.jsp</welcome-file>-->
<!--</welcome-file-list>-->
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 加载类路径(classpath:)下的属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 开启注解,采用注解的方式 -->
<context:annotation-config />
<!-- 扫描 com.merryyou包下的带注解的组件 -->
<context:component-scan base-package="com.merryyou" />
<!-- 配置spring自带的数据源数据库 -->
<!--<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/userdb" />
<property name="username" value="root" />
<property name="password" value="admin" />
</bean>-->
<!--配置c3p0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.main.driverClass}" />
<property name="jdbcUrl" value="${jdbc.main.jdbcUrl}?zeroDateTimeBehavior=convertToNull" />
<property name="user" value="${jdbc.main.user}" />
<property name="password" value="${jdbc.main.password}" />
<property name="minPoolSize" value="${jdbc.main.minPoolSize}" />
<property name="maxPoolSize" value="${jdbc.main.maxPoolSize}" />
<property name="initialPoolSize" value="${jdbc.main.initialPoolSize}" />
<property name="acquireIncrement" value="${jdbc.main.acquireIncrement}" />
<property name="acquireRetryAttempts" value="${jdbc.main.acquireRetryAttempts}" />
</bean>
<!-- 配置事物管理器(基于注解) -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启事物注解 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 扫描 com.merryyou包下的带注解的组件 -->
<context:component-scan base-package="com.merryyou"/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<!--<mvc:resources mapping="/js/**" location="/assets/js/" />-->
<!--<mvc:resources mapping="/css/**" location="/assets/css/" />-->
<!--<mvc:resources mapping="/images/**" location="/assets/images/" />-->
<!--<context:annotation-config />-->
<!--<mvc:annotation-driven />-->
<mvc:annotation-driven content-negotiation-manager="contentManager"/>
<bean id="contentManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="true"/>
<property name="ignoreAcceptHeader" value="true" />
<property name="defaultContentType" value="text/html" />
<property name="useJaf" value="false"/>
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="html" value="text/html" />
<entry key="xml" value="application/xml" />
</map>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
package com.merryyou.controller.api;
import com.merryyou.domain.User;
import com.merryyou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created on 2015/9/24 0024.
*
* @author zhenglongfei
* @since 1.0
*/
@RestController
@RequestMapping("/authUser")
public class AuthUserController {
@Autowired
private UserService userService;
@RequestMapping(value = "/list",method = RequestMethod.GET,produces={ "application/xml","application/json"})
public List list() throws Exception{
List<User> userList = userService.getUserList();
System.out.print("*****************");
return userList;
}
}
@RequestMapping(value = { "/User/{id}", "/user/{id}.json" }, method = RequestMethod.GET,produces={ "application/xml","application/json"})
public @ResponseBody User getUser(@PathVariable String id, HttpServletRequest request, HttpServletResponse response)
throws Exception {
logger.info("getUser-------------->id=" + id);
User u = userService.getUser(1);
return u;
}
@ResponseBody