@RequestMapping(value = {“list“, ““}) 的作用

@RequestMapping(value = {“list”, “”}) 的作用

adminPath:www.baidu.com

在项目里,我们可能有些请求是可以通过两个路劲,访问同一个Controller 里面的方法的,所以,我们可以使用以上的方式,来实现 例如:@RequestMapping(value = “${adminPath}/integral”) 积分的请求访问的时候, 我们两个请求 www.baidu.com/integral 或者 www.baidu.com/integral/list 都是访问同一个方法

感谢笔记,让自己学而知不足。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.org.core.entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @Entity public class User { @Id @GeneratedValue private int id; @Column(name = "username") private String username; @Column(name = "password") private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } package com.org.core.service.impl; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.org.core.dao.UserDao; import com.org.core.entity.User; import com.org.core.service.UserService; /** *@Author:liangjilong *@Date:2014-2-25 *@Version:1.0 *@Description: */ @Service public class UserServiceImpl implements UserService{ @Resource private UserDao userDao; @Override public List<User> getListUsers() { return userDao.getListUsers(); } } package com.org.core.dao.impl; import java.util.List; import javax.annotation.Resource; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.stereotype.Repository; import com.org.core.dao.UserDao; import com.org.core.entity.User; /** *@Author:liangjilong *@Date:2014-2-25 *@Version:1.0 *@Description: */ @Repository public class UserDaoImpl implements UserDao { @Resource private HibernateTemplate hibernateTemplate; @SuppressWarnings("unchecked") public List<User> getListUsers() { String hql="From User"; List<User> lists=hibernateTemplate.find(hql); return lists; } } package com.org.core.action; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.org.core.entity.User; import com.org.core.service.UserService; import com.org.utils.servlet.ServletUtils; /** *@Author:liangjilong *@Date:2014-2-25 *@Version:1.0 *@Description: */ @Controller public class UserController{ @Resource private UserService userService; @RequestMapping(value="/userList1.do") public String geUserList1(HttpServletRequest request ,HttpServletResponse response) throws Exception { List<User> lists=userService.getListUsers(); if(lists!=null){ //request.setAttribute("userList", lists); ServletUtils.setRequestValue("userList", lists); } return "/user/userList";//user文件下的userList.jsp } @RequestMapping(value="/userList2.do") public ModelAndView geUserList2(HttpServletRequest request ,HttpServletResponse response) throws Exception { List<User> lists=userService.getListUsers(); if(lists!=null){ //request.setAttribute("userList", lists); ServletUtils.setRequestValue("userList", lists); } return new ModelAndView("/user/userList"); } } <?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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-lazy-init="true"> <context:annotation-config/> <!-- 扫描包 --> <context:component-scan base-package="com.org.core"/> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 配置jdbc --> <bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean> <!-- 配置數據源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- 连接池启动的初始值 --> <property name="initialSize" value="1"/> <property name="maxActive" value="500"/> <property name="maxIdle" value="2"/> <property name="minIdle" value="1"/> </bean> <!-- 配置sessionFactory 注解配置 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean 配置形式: org.springframework.orm.hibernate3.LocalSessionFactoryBean --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.org.core.entity</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <!-- 配置hibernateTemplate --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- Spring AOP config配置切点 --> <aop:config> <aop:pointcut expression="execution(public * com.org.core.service.*.*(..))" id="bussinessService" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> </aop:config> <!-- 配置那个类那个方法用到事务处理 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> </beans>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值