网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

mybatis自动生成代码及使用

mybatis自动生成代码及使用

1.新建maven项目

专注于为中小企业提供成都网站建设、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业应城免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

2.项目基础配置

找到maven工程所在目录下org.eclipse.wst.common.project.facet.core.xml此文件
mybatis自动生成代码及使用

修改成如下内容

mybatis自动生成代码及使用

maven工程下的web.xml文件替换为




pom.xml文件中修改build节点,添加如下内容

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

3.在pom.xml追加如下内容


    org.mybatis.generator
    mybatis-generator-core
    1.3.2

    org.mybatis.generator
    mybatis-generator-maven-plugin
    1.3.2
    
        
        src/main/resources/generatorConfig.xml
        true
        true
    
    
        
        
            MySQL
            mysql-connector-java
            5.1.34
        
                
    
        
            Generate MyBatis Artifacts
            
                generate
            
        
    

4.在src/main/resources文件下创建generatorConfig.xml,内容如下







    
    
        
        
            
        

        
        
        

        
        
            
            
        

        
        
            
        

        
        
            
        

        
        

5.右键项目--》run As--》Maven build--》输入mybatis-generator:generate,即可创建成功。

mybatis自动生成代码及使用

6.生成代码如下

package com.lymn.it.mapper;

import com.lymn.it.model.User;

public interface UserMapper {
    int deleteByPrimaryKey(Integer userid);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Integer userid);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

}



  
    
    
    
    
    
    
    
  
  
    userid, username, password, email, phone, status, code
  
  
  
    delete from user
    where userid = #{userid,jdbcType=INTEGER}
  
  
    insert into user (userid, username, password, 
      email, phone, status, 
      code)
    values (#{userid,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, 
      #{email,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, 
      #{code,jdbcType=VARCHAR})
  
  
    insert into user
    
      
        userid,
      
      
        username,
      
      
        password,
      
      
        email,
      
      
        phone,
      
      
        status,
      
      
        code,
      
    
    
      
        #{userid,jdbcType=INTEGER},
      
      
        #{username,jdbcType=VARCHAR},
      
      
        #{password,jdbcType=VARCHAR},
      
      
        #{email,jdbcType=VARCHAR},
      
      
        #{phone,jdbcType=VARCHAR},
      
      
        #{status,jdbcType=VARCHAR},
      
      
        #{code,jdbcType=VARCHAR},
      
    
  
  
    update user
    
      
        username = #{username,jdbcType=VARCHAR},
      
      
        password = #{password,jdbcType=VARCHAR},
      
      
        email = #{email,jdbcType=VARCHAR},
      
      
        phone = #{phone,jdbcType=VARCHAR},
      
      
        status = #{status,jdbcType=VARCHAR},
      
      
        code = #{code,jdbcType=VARCHAR},
      
    
    where userid = #{userid,jdbcType=INTEGER}
  
  
    update user
    set username = #{username,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      status = #{status,jdbcType=VARCHAR},
      code = #{code,jdbcType=VARCHAR}
    where userid = #{userid,jdbcType=INTEGER}
  

package com.lymn.it.model;

public class User {
    private Integer userid;

    private String username;

    private String password;

    private String email;

    private String phone;

    private String status;

    private String code;

    public Integer getUserid() {
        return userid;
    }

    public void setUserid(Integer userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? null : phone.trim();
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status == null ? null : status.trim();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code == null ? null : code.trim();
    }
}

8.参照SSM框架搭建之传统方式(一)博客中的service、controller层进行测试


当前名称:mybatis自动生成代码及使用
文章位置:http://bjjierui.cn/article/ishopd.html

其他资讯