Maven+Spring+SpringMVC+Mybatis

Maven+Spring+SpringMVC+Mybatis
항목 주의 사항
인 코딩: UTF - 8 jdk:1.7
컴 파일 환경: 1.7 build path:1.7
부도


접근 경로
http://localhost:8066/selectUsers.action
주: 8066 변경 하지 마 십시오. 이것 은 pom. xml 에서 tomcat 플러그 인 에 설정 되 어 있 습 니 다
먼저 보 는 것 이 즐겁다.


기능 소개
Maven 을 통 해 Spring, SpringMVC, Mybatis 관리
페이지 전시 데이터베이스 정보 [주요 기능] 추가, 삭제, 업데이트 정 보 는 js 를 통 해 [부차적인 기능] 을 보 여 줍 니 다.
프로젝트 구조

데이터베이스 디자인
데이터베이스 이름
springmvc_db

시계
user

표 구조


구체 코드
src
main
java
com
peng
controller
UserServlet.java
package com.peng.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.peng.pojo.User;
import com.peng.service.UserService;

@Controller(value = "userServlet")
public class UserServlet {
    @Autowired
    @Qualifier(value = "userService")
    private UserService userService;

    @RequestMapping("/selectUsers.action")
    public String findAllAction(Model model) {
        List user_list = userService.selectUsers();
        System.out.println(user_list);
        model.addAttribute("user_list", user_list);
        return "users";
    }
}


mapper
UserMapper.java
package com.peng.mapper;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.peng.pojo.User;

@Repository(value = "userMapper")
public interface UserMapper {
    public List selectUsers();
}


pojo
User.java
package com.peng.pojo;

import java.io.Serializable;

@SuppressWarnings("serial")
public class User implements Serializable {
    private String id;
    private String name;
    private String email;
    private String money;

    public User() {
        super();
    }

    public User(String id, String name, String emial, String money) {
        super();
        this.id = id;
        this.name = name;
        this.email = emial;
        this.money = money;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmial() {
        return email;
    }

    public void setEmial(String emial) {
        this.email = emial;
    }

    public String getMoney() {
        return money;
    }

    public void setMoney(String money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return "【  :" + id + "  :" + name + ",  :" + email + ",  :" + money + "】";
    }

}

UserMapper.xml



    



service
UserService.java
package com.peng.service;

import java.util.List;

import com.peng.pojo.User;

public interface UserService {
    /**
     *        
     * 
     * @return
     */
    List selectUsers();

}

UserServiceImpl.java
package com.peng.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.peng.mapper.UserMapper;
import com.peng.pojo.User;

@Service(value = "userService")
public class UserServiceImpl implements UserService {

    //   dao   
    @Autowired
    @Qualifier(value = "userMapper")
    private UserMapper userMapper;

    public List selectUsers() {
        return userMapper.selectUsers();
    }

}





resources
applicationContext.xml


    
    
    
    
    
    
        
        
        
        
        
        
    
    
    
        
    
    
    
        
    
    
    
        
        
        
        
              
          
         
    


applivationContext-mvc.xml


    
    
    
    
    
    
        
        
        
    
    
    
        
        
        
    


jdbc_config.properties
jdbc.user=root
jdbc.password=root
jdbc.url=jdbc\:mysql\://localhost\:3306/springmvc_db
jdbc.driver=com.mysql.jdbc.Driver

log4j.properties
log4j.rootLogger=DEBUG, Console
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG                

sqlMapConfig.xml



                


webapp
js
jquery js  (          )

WEB-INF
message.jsp




My JSP 'index.jsp' starting page



    success!
    

users.jsp






    






    $(function() {
        $("#add").click(
                function() {
                    //      
                    var id = $("#box1 input[name='id']").val().trim();
                    var name = $("#box1 input[name='name']").val().trim();
                    var email = $("#box1 input[name='email']").val().trim();
                    var salary = $("#box1 input[name='salary']").val().trim();
                    //  
                    if (id == "" || name == "" || email == "" || salary == "") {
                        alert("        ");
                        return;
                    }
                    //  id    
                    var flag = false;
                    $("table tr").each(function() {
                        if ($(this).find("td:eq(1)").text() == id) {
                            alert("ID   ");
                            flag = true;
                            return false;
                        }
                    });
                    if (flag) {
                        return;
                    }
                    //           
                    var $tab = $("table");
                    var $tr = $("<tr></tr>");
                    var $td0 = $("<td><input type='checkbox'/></td>");
                    var $td1 = $("<td>" + id + "</td>");
                    var $td2 = $("<td>" + name + "</td>");
                    var $td3 = $("<td>" + email + "</td>");
                    var $td4 = $("<td>" + salary + "</td>");
                    $tr.append($td0).append($td1).append($td2).append($td3)
                            .append($td4);
                    $tab.append($tr);

                });
        //    
        $("#all").click(function() {
            //      
            var check = $(this).attr("checked");
            //             
            $("table input").attr("checked", check);
        });
        //  
        $("#del").click(function() {
            $("input:checked:not(input[id='all'])").parents("tr").remove();
        });
        //  
        $("#upd").click(function() {
            //      
            var id = $("#box2 input[name='id']").val().trim();
            var name = $("#box2 input[name='name']").val().trim();
            var email = $("#box2 input[name='email']").val().trim();
            var salary = $("#box2 input[name='salary']").val().trim();

            //  
            if (id == "" || name == "" || email == "" || salary == "") {
                alert("        ");
                return;
            }
            //  ID     
            var flag = true;
            $("table tr").each(function() {
                if ($(this).find("td:eq(1)").text() == id) {
                    //    
                    flag = false;
                    $(this).find("td:eq(2)").text(name);
                    $(this).find("td:eq(3)").text(email);
                    $(this).find("td:eq(4)").text(salary);
                    return false;

                }
            });
            if (flag) {
                alert("  id   !");
            }

        });

    });




    

ID:

ID
${item.id} ${item.name} ${item.emial} ${item.money}

선택 삭제


ID:

web.xml



    
    
    
        characterFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            utf-8
        
        
            forceEncoding
            true
        
    
    
        characterFilter
        /*
    
    
    
        springmvc_dispatcher
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:/applicationContext*.xml
        
    
    
    
        springmvc_dispatcher
        *.action
    
    
    
        index.jsp
    



index.jsp


Hello World!




test
java


pom.xml

    4.0.0
    com.peng
    ssmm
    war
    0.0.1-SNAPSHOT
    ssmm Maven Webapp
    http://maven.apache.org
    
        
        4.0.2.RELEASE
        
        3.2.6
        
        1.7.7
        1.2.17
    
    
        
            c3p0
            c3p0
            0.9.1.2
        
        
            junit
            junit
            3.8.1
            test
        
        
        
            org.springframework
            spring-core
            ${spring.version}
        

        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-oxm
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        

        
            org.springframework
            spring-jdbc
            ${spring.version}
        

        
            org.springframework
            spring-webmvc
            ${spring.version}
        
        
            org.springframework
            spring-aop
            ${spring.version}
        

        
            org.springframework
            spring-context-support
            ${spring.version}
        

        
            org.springframework
            spring-test
            ${spring.version}
        
        
        
            org.mybatis
            mybatis
            ${mybatis.version}
        
        
        
            org.mybatis
            mybatis-spring
            1.2.2
        

        
        
            mysql
            mysql-connector-java
            5.1.30
        

        
        
            commons-dbcp
            commons-dbcp
            1.2.2
        
        
        
            jstl
            jstl
            1.2
        
        
        
        
            log4j
            log4j
            ${log4j.version}
        


        
        
            com.alibaba
            fastjson
            1.1.41
        


        
            org.slf4j
            slf4j-api
            ${slf4j.version}
        

        
            org.slf4j
            slf4j-log4j12
            ${slf4j.version}
        
        
        
        
            org.codehaus.jackson
            jackson-mapper-asl
            1.9.13
        
        
        
            commons-fileupload
            commons-fileupload
            1.3.1
        
        
            commons-io
            commons-io
            2.4
        
        
            commons-codec
            commons-codec
            1.9
        
    
    
        
            
            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.2
                
                    8066
                    
                    /
                
            
        
    

좋은 웹페이지 즐겨찾기