zoukankan      html  css  js  c++  java
  • 第48月第18天 spring整合springmvc

    1.

    web.xml

      <!--*****************************Spring整合SpringMvc配置 start*****************************-->
      <!--配置Spring的监听器,默认只加载WEB-INF目录下的applicationContext.xml配置文件-->
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <!--设置spring配置文件的路径-->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <!--resource中的文件会打包发布到WEB-INF/classes类目录下,所以前面要加classpath-->
        <param-value>classpath:spring.xml</param-value>
      </context-param>
      <!--*****************************Spring整合SpringMvc配置 end-*****************************-->

    spring.xml

    <?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:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">
    
        <!--*****************************spring配置 start*****************************-->
        <!--注解的扫描,希望处理service和dao,controller不需要Spring框架去处理-->
        <context:component-scan base-package="cn.itcast">
            <!--配置哪些注解不扫描-->
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
        <!--*****************************spring配置 end*****************************-->
    </beans>
    IAccountService.java

    package cn.itcast.service;
    
    import cn.itcast.domain.Account;
    
    import java.util.List;
    
    public interface IAccountService {
        List<Account> findAll();
    
        void saveAccount(Account account);
    
    }
    AccountServiceImpl.java
    package cn.itcast.service.impl;
    
    import cn.itcast.domain.Account;
    import cn.itcast.service.IAccountService;
    import org.springframework.stereotype.Service;
    
    import java.util.List;
    
    @Service("accountService")
    public class AccountServiceImpl implements IAccountService {
    
    
        @Override
        public List<Account> findAll() {
            System.out.println("執行 findAll");
            return null;
        }
    
        @Override
        public void saveAccount(Account account) {
            System.out.println(("執行 saveAccount"));
        }
    }

    AjaxController

    @RestController
    public class AjaxController {
        @Autowired
        private IAccountService accountService;
    
    
        @RequestMapping("/a2")
        public ResultModel ajax2(){
            System.out.println("AccountController findAll");
            List<Account> accountList = accountService.findAll();
    
            return ResultModel.success("111");
    //        return "111"; //由于@RestController注解,将list转成json格式返回
        }
    
    
    }
  • 相关阅读:
    neutron外网介绍
    oracle时间转换问题汇总
    redhat72普通用户计划任务实现守护进程
    Rabbitmq消息持久化
    rabbitmq消息流转分析
    Rabbitmq基本概念
    protobuf传文件存入oracle
    X32指令自动委托
    IT系统上线事宜
    可转债业务玩法
  • 原文地址:https://www.cnblogs.com/javastart/p/13692001.html
Copyright © 2011-2022 走看看