注解方式配置springmvc(idea)

注解方式配置springmvc(idea)

在上篇博客的基础上,我只写不一样的地方

上篇博客:https://blog.csdn.net/qq_42370505/article/details/106566293

不同点一:

<?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:bean="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.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--配置扫描包-->
   <bean:component-scan base-package="com.lxz.controller"/>
    <!--处理静态资源的方式标签(这里是处理servlet的方式)-->
    <mvc:default-servlet-handler/>
     <!--注解驱动-->
    <mvc:annotation-driven/>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
     </bean>
    
</beans>

不同点二:

package com.lxz.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
 * @auther:
 * @creater:
 * @time
 **/
@Controller
//@RequestMapping("/abc")
public class HelloController  {
//    这里的RequestMapping就相当于<bean id="/hellospringmvc" class="com.lxz.controller.HelloController"></bean>
    //如果类前没有@RequestMapping("/abc")这里相当于localhost:8080//hello,如果方法前有,则此时为:localhost:8080//abc/hello,
    //当然一般情况下都是不在类前加@RequestMapping这个的,为了怕遗忘,如果真的要加可以直接在方法前改为 @RequestMapping("/abc/hello")
    @RequestMapping("/abc/hello")
  public String hello(Model md)
  {
      md.addAttribute("msg","你好世界");
      return "test";
  }
}

其余的基本一样,接下来可以专注写业务逻辑代码了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值