2018-02-18-01.各个配置文件头

mybatis:

sqlMapConfig.xml







UserMapper.xml(注意命名空间不要漏)





db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8
jdbc.username=root
jdbc.password=12345

log4j.properties

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

spring整合mybatis

applicationContext.xml




   
   

    
    
        
        
        
        
        
        
    

    
    
        
        
        
        
    


    
        
    

    
    



    
    


注意:springmvc和spring整合是无缝的,所以并不需要在spring文件中专门去配置springmvc的读取注入等

springmvc.xml




    
    

    
    

    
    
    
        
        
        
        
    


web.xml



    springmvc-web
    
        index.html
        index.htm
        index.jsp
        default.html
        default.htm
        default.jsp
    

    
    
        contextConfigLocation
        classpath:spring/applicationContext*.xml
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        springmvc-web
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:spring/springmvc.xml
        
    

    
        
        springmvc-web
        
        *.action
    


controller层

@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    /**
     * 显示商品列表
     * 
     * @return
     */
    @RequestMapping("/itemList")
    public ModelAndView queryItemList() {
        // 获取商品数据,service,dao,pojo层就不展示了,只是正常数据库查询逻辑而已
        List list = this.itemService.queryItemList();

        ModelAndView modelAndView = new ModelAndView();
        // 把商品数据放到模型中
        modelAndView.addObject("itemList", list);
        // 设置逻辑视图
        modelAndView.setViewName("itemList");

        return modelAndView;
    }

}

测试:
访问url:
http://127.0.0.1:8080/springmvc-web/itemList.action

效果如下图:


你可能感兴趣的:(2018-02-18-01.各个配置文件头)