spring环境准备

springMVC环境搭建与逆向工程使用-学习笔记_第1张图片

package com.java.springmvc.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import pojo.Items;

@Controller
public class ItemController {

    @RequestMapping(value = "itemlist.action")
    public ModelAndView itemList(){

        // 创建页面需要显示的商品数据
        List list = new ArrayList();
        list.add(new Items(1, "1华为 荣耀8", 2399f, new Date(), "质量好!1"));
        list.add(new Items(2, "2华为 荣耀8", 2399f, new Date(), "质量好!2"));
        list.add(new Items(3, "3华为 荣耀8", 2399f, new Date(), "质量好!3"));
        list.add(new Items(4, "4华为 荣耀8", 2399f, new Date(), "质量好!4"));
        list.add(new Items(5, "5华为 荣耀8", 2399f, new Date(), "质量好!5"));
        list.add(new Items(6, "6华为 荣耀8", 2399f, new Date(), "质量好!6"));

        ModelAndView mav = new ModelAndView();
        //数据
        mav.addObject("itemList",list);
        mav.setViewName("itemList");
        return mav;
    }

}

环境配置

springmvc.xml





    
    

    
    
    
    
    
    

    
    
        
        
    

web.xml



    spri4
    
        index.html
        index.htm
        index.jsp
        default.html
        default.htm
        default.jsp
    

    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:springmvc.xml
        
    

    
        springmvc
        
        *.action
    

lib

springMVC环境搭建与逆向工程使用-学习笔记_第2张图片

jsp页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>




查询商品列表

 
查询条件:
商品列表:
商品名称 商品价格 生产日期 商品描述 操作
${item.name } ${item.price } ${item.detail } 修改

逆相工程

java main

package generatorSqlmapCustom;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

public class GeneratorSqlmap {

    public void generator() throws Exception{

        List warnings = new ArrayList();
        boolean overwrite = true;
        //指定 逆向工程配置文件
        File configFile = new File("generatorConfig.xml"); 
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                callback, warnings);
        myBatisGenerator.generate(null);

    } 
    public static void main(String[] args) throws Exception {
        try {
            GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
            generatorSqlmap.generator();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

generatorConfig.xml





    
        
            
            
        
        
        
        
        

        
        
            
        

        
        
            
            
            
            
        
        
        
            
            
        
        
        
            
            
        
        
        

lib

springMVC环境搭建与逆向工程使用-学习笔记_第3张图片