spring+springmvc+mybatis-plus 純注解開發


最近剛完成一個項目,剛好有一點時間,來完成基於spring+springmvc+mybatis-plus 純注解開發

一、創建工程、導入依賴

1、新建一個基於maven的web工程,使用JDK1.8

 

 

 

 

 

 

 

 

 

 2、調整目錄結構

2.1、新建java

 

 

 

 

2.2、新建resources

 

 

2.3、刪除web.xml、構建基礎包

 

 

 

 

 

 2.4、工程目錄構建完成展示

2、配置tomcat服務器

2.1、服務器配置

 

 

 

 

 

 

 

 

 

 2.2、測試服務器配置

 

 

3、pom.xml文件配置

  1 <properties>
  2     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3     <maven.compiler.source>1.8</maven.compiler.source>
  4     <maven.compiler.target>1.8</maven.compiler.target>
  5   </properties>
  6 
  7   <dependencies>
  8     <dependency>
  9       <groupId>org.springframework</groupId>
 10       <artifactId>spring-context</artifactId>
 11       <version>5.1.5.RELEASE</version>
 12     </dependency>
 13     <dependency>
 14       <groupId>org.springframework</groupId>
 15       <artifactId>spring-core</artifactId>
 16       <version>5.1.5.RELEASE</version>
 17     </dependency>
 18     <dependency>
 19       <groupId>org.springframework</groupId>
 20       <artifactId>spring-beans</artifactId>
 21       <version>5.1.5.RELEASE</version>
 22     </dependency>
 23     <dependency>
 24       <groupId>org.springframework</groupId>
 25       <artifactId>spring-web</artifactId>
 26       <version>5.1.5.RELEASE</version>
 27     </dependency>
 28     <dependency>
 29       <groupId>org.springframework</groupId>
 30       <artifactId>spring-webmvc</artifactId>
 31       <version>5.1.5.RELEASE</version>
 32     </dependency>
 33     <dependency>
 34       <groupId>org.springframework</groupId>
 35       <artifactId>spring-aop</artifactId>
 36       <version>5.1.5.RELEASE</version>
 37     </dependency>
 38     <dependency>
 39       <groupId>org.springframework</groupId>
 40       <artifactId>spring-tx</artifactId>
 41       <version>5.1.5.RELEASE</version>
 42     </dependency>
 43     <dependency>
 44       <groupId>org.springframework</groupId>
 45       <artifactId>spring-jdbc</artifactId>
 46       <version>5.1.5.RELEASE</version>
 47     </dependency>
 48     <dependency>
 49       <groupId>org.mybatis</groupId>
 50       <artifactId>mybatis-spring</artifactId>
 51       <version>1.3.2</version>
 52     </dependency>
 53     <dependency>
 54       <groupId>org.mybatis</groupId>
 55       <artifactId>mybatis</artifactId>
 56       <version>3.4.6</version>
 57     </dependency>
 58     <dependency>
 59       <groupId>com.baomidou</groupId>
 60       <artifactId>mybatis-plus</artifactId>
 61       <version>3.0.7.1</version>
 62     </dependency>
 63     <dependency>
 64       <groupId>com.baomidou</groupId>
 65       <artifactId>mybatis-plus-generator</artifactId>
 66       <version>3.0.7.1</version>
 67     </dependency>
 68     <dependency>
 69       <groupId>org.apache.velocity</groupId>
 70       <artifactId>velocity-engine-core</artifactId>
 71       <version>2.0</version>
 72     </dependency>
 73     <dependency>
 74       <groupId>org.apache.commons</groupId>
 75       <artifactId>commons-lang3</artifactId>
 76       <version>3.7</version>
 77     </dependency>
 78     <dependency>
 79       <groupId>com.fasterxml.jackson.core</groupId>
 80       <artifactId>jackson-core</artifactId>
 81       <version>2.9.8</version>
 82     </dependency>
 83     <dependency>
 84       <groupId>com.fasterxml.jackson.core</groupId>
 85       <artifactId>jackson-databind</artifactId>
 86       <version>2.9.8</version>
 87     </dependency>
 88     <dependency>
 89       <groupId>com.fasterxml.jackson.core</groupId>
 90       <artifactId>jackson-annotations</artifactId>
 91       <version>2.9.8</version>
 92     </dependency>
 93     <dependency>
 94       <groupId>com.oracle</groupId>
 95       <artifactId>ojdbc6</artifactId>
 96       <version>11.2.0.1.0</version>
 97     </dependency>
 98     <dependency>
 99       <groupId>mysql</groupId>
100       <artifactId>mysql-connector-java</artifactId>
101       <version>6.0.5</version>
102     </dependency>
103     <dependency>
104       <groupId>com.mchange</groupId>
105       <artifactId>c3p0</artifactId>
106       <version>0.9.5.2</version>
107     </dependency>
108     <dependency>
109       <groupId>com.mchange</groupId>
110       <artifactId>c3p0</artifactId>
111       <version>0.9.5.2</version>
112     </dependency>
113     <dependency>
114       <groupId>com.alibaba</groupId>
115       <artifactId>druid</artifactId>
116       <version>1.1.10</version>
117     </dependency>
118     <dependency>
119       <groupId>org.projectlombok</groupId>
120       <artifactId>lombok</artifactId>
121       <version>1.18.8</version>
122       <scope>provided</scope>
123     </dependency>
124     <dependency>
125       <groupId>junit</groupId>
126       <artifactId>junit</artifactId>
127       <version>4.11</version>
128       <scope>test</scope>
129     </dependency>
130     <dependency>
131       <groupId>javax.servlet</groupId>
132       <artifactId>javax.servlet-api</artifactId>
133       <version>3.1.0</version>
134       <scope>provided</scope>
135     </dependency>
136   </dependencies>
137 
138   <build>
139     <finalName>loginannotationday02</finalName>
140     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
141       <plugins>
142         <plugin>
143           <artifactId>maven-clean-plugin</artifactId>
144           <version>3.1.0</version>
145         </plugin>
146         <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
147         <plugin>
148           <artifactId>maven-resources-plugin</artifactId>
149           <version>3.0.2</version>
150         </plugin>
151         <plugin>
152           <artifactId>maven-compiler-plugin</artifactId>
153           <version>3.8.0</version>
154         </plugin>
155         <plugin>
156           <artifactId>maven-surefire-plugin</artifactId>
157           <version>2.22.1</version>
158         </plugin>
159         <plugin>
160           <artifactId>maven-war-plugin</artifactId>
161           <version>3.2.2</version>
162         </plugin>
163         <plugin>
164           <artifactId>maven-install-plugin</artifactId>
165           <version>2.5.2</version>
166         </plugin>
167         <plugin>
168           <artifactId>maven-deploy-plugin</artifactId>
169           <version>2.8.2</version>
170         </plugin>
171       </plugins>
172     </pluginManagement>
173   </build>

二、編寫mybatis-plus的代碼生成工具

調整目錄結構

 

 

 在util下新建mybatis代碼生成工具類

 

 

 mybatisplusutil代碼如下

  1 package com.cxw.util;
  2 
  3 import com.baomidou.mybatisplus.annotation.DbType;
  4 import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
  5 import com.baomidou.mybatisplus.core.toolkit.StringPool;
  6 import com.baomidou.mybatisplus.generator.AutoGenerator;
  7 import com.baomidou.mybatisplus.generator.InjectionConfig;
  8 import com.baomidou.mybatisplus.generator.config.*;
  9 import com.baomidou.mybatisplus.generator.config.converts.OracleTypeConvert;
 10 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
 11 import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
 12 import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
 13 import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
 14 import org.apache.commons.lang3.StringUtils;
 15 
 16 import java.util.ArrayList;
 17 import java.util.List;
 18 import java.util.Scanner;
 19 
 20 public class MybatisPlusUtil{
 21 
 22     /**
 23      * <p>
 24      * 讀取控制台內容
 25      * </p>
 26      */
 27     static String Scanner(String tip) {
 28         Scanner scanner = new Scanner(System.in);
 29         StringBuilder help = new StringBuilder();
 30         help.append("請輸入" + tip + ":");
 31         System.out.println(help.toString());
 32         if (scanner.hasNext()) {
 33             String ipt = scanner.next();
 34             if (StringUtils.isNotEmpty(ipt)) {
 35                 return ipt;
 36             }
 37         }
 38         throw new MybatisPlusException("請輸入正確的" + tip + "!");
 39     }
 40 
 41     public static void main(String[] args) {
 42         //代碼生成器
 43         AutoGenerator autoGenerator = new AutoGenerator();
 44 
 45         //全局配置
 46         GlobalConfig globalConfig = new GlobalConfig();
 47         final  String projectPath = System.getProperty("user.dir");
 48         globalConfig.setOutputDir(projectPath + "/src/main/java");
 49         globalConfig.setAuthor("cxw");
 50 //        globalConfig.setOpen(false);
 51         //是否覆蓋文件
 52         globalConfig.setFileOverride(true);
 53         //不需要ActiveRecord特性的請改為false
 54         globalConfig.setActiveRecord(false);
 55         //XML 二級緩存
 56         globalConfig.setEnableCache(false);
 57         //XML ResultMap
 58         globalConfig.setBaseResultMap(true);
 59         //XML columList
 60         globalConfig.setBaseColumnList(false);
 61         autoGenerator.setGlobalConfig(globalConfig);
 62 
 63         //數據源配置
 64         DataSourceConfig dataSourceConfig = new DataSourceConfig();
 65         dataSourceConfig.setDbType(DbType.MYSQL);
 66         //類型轉換
 67         dataSourceConfig.setTypeConvert(new OracleTypeConvert(){
 68             @Override
 69             public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
 70                 return super.processTypeConvert(globalConfig, fieldType);
 71             }
 72         });
 73         dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/cxwdb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false");
 74         dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
 75         dataSourceConfig.setUsername("root");
 76         dataSourceConfig.setPassword("123456");
 77         autoGenerator.setDataSource(dataSourceConfig);
 78 
 79 
 80 
 81         //包配置
 82         final PackageConfig packageConfig = new PackageConfig();
 83         //基礎包名
 84         packageConfig.setParent("com.cxw");
 85         //模塊名
 86         packageConfig.setModuleName(Scanner("模塊名"));
 87         packageConfig.setService("service");
 88         packageConfig.setServiceImpl("service.impl");
 89         packageConfig.setEntity("entity");
 90         packageConfig.setController("controller");
 91         packageConfig.setMapper("mapper");
 92         packageConfig.setXml("mapper");
 93         autoGenerator.setPackageInfo(packageConfig);
 94 
 95         // 自定義配置
 96         InjectionConfig injectionConfig = new InjectionConfig() {
 97             @Override
 98             public void initMap() {
 99                 // to do nothing
100             }
101         };
102         List<FileOutConfig> focList = new ArrayList<>();
103         focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
104             @Override
105             public String outputFile(TableInfo tableInfo) {
106                 // 自定義輸入文件名稱
107                 return projectPath + "/src/main/resources/mapper/" + packageConfig.getModuleName()
108                         + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
109             }
110         });
111         injectionConfig.setFileOutConfigList(focList);
112         autoGenerator.setCfg(injectionConfig);
113         autoGenerator.setTemplate(new TemplateConfig().setXml(null));
114 
115         // 策略配置
116         StrategyConfig strategy = new StrategyConfig();
117         strategy.setNaming(NamingStrategy.underline_to_camel);
118         strategy.setColumnNaming(NamingStrategy.underline_to_camel);
119         strategy.setEntityLombokModel(false);
120         strategy.setRestControllerStyle(true);
121         strategy.setCapitalMode(true);
122         strategy.setInclude(Scanner("表名"));
123         strategy.setControllerMappingHyphenStyle(true);
124         strategy.setEntityTableFieldAnnotationEnable(true);
125 //        strategy.setTablePrefix("n_");
126         autoGenerator.setStrategy(strategy);
127         autoGenerator.setTemplateEngine(new VelocityTemplateEngine());
128         autoGenerator.execute();
129     }
130 }

通過工具類生成代碼

 

 

 生成后目錄結構如下

三、spring+springmvc+mybatis-plus 純注解搭建

1、構建核心配置文件

 1 package com.cxw.config;
 2 
 3 import org.springframework.context.annotation.ComponentScan;
 4 import org.springframework.context.annotation.Configuration;
 5 import org.springframework.context.annotation.FilterType;
 6 import org.springframework.stereotype.Controller;
 7 
 8 
 9 @Configuration
10 @ComponentScan(basePackages = {"com.cxw"},excludeFilters = {
11         @ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class),
12 })
13 /**
14  * 核心配置文件
15  */
16 public class AppConfig {
17 
18 }

2、構建springmvc配置文件

 1 package com.cxw.config;
 2 
 3 import org.springframework.context.annotation.ComponentScan;
 4 import org.springframework.context.annotation.Configuration;
 5 import org.springframework.context.annotation.FilterType;
 6 import org.springframework.stereotype.Controller;
 7 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 8 
 9 @Configuration
10 @ComponentScan(basePackages = "com.cxw",
11     includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,
12     value = Controller.class)})
13 @EnableWebMvc
14 /**
15  * springmvc配置文件
16  */
17 public class WebConfig {
18 
19 }

3、構建數據庫配置文件

 

 

 

1 spring.datasource.user=root
2 spring.datasource.password=123456
3 spring.datasource.driver=com.mysql.cj.jdbc.Driver
4 spring.datasource.url=jdbc:mysql://localhost:3306/cxwdb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false

4、構建數據庫配置文件關聯文件

 1 package com.cxw.config;
 2 
 3 import lombok.Data;
 4 import org.springframework.beans.factory.annotation.Value;
 5 import org.springframework.context.annotation.Configuration;
 6 import org.springframework.context.annotation.PropertySource;
 7 
 8 @PropertySource("classpath:db.properties")
 9 @Data
10 @Configuration
11 public class PropertyConfig {
12 
13     @Value("${spring.datasource.url}")
14     private String url;
15     @Value("${spring.datasource.driver}")
16     private String driver;
17     @Value("${spring.datasource.user}")
18     private String user;
19     @Value("${spring.datasource.password}")
20     private String password;
21 
22 }

5、構建mybatisplus配置文件

 1 package com.cxw.config;
 2 
 3 import com.alibaba.druid.pool.DruidDataSource;
 4 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
 5 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 6 import org.mybatis.spring.annotation.MapperScan;
 7 import org.springframework.context.annotation.Bean;
 8 import org.springframework.context.annotation.Configuration;
 9 
10 import javax.sql.DataSource;
11 
12 @Configuration
13 @MapperScan(value = "com.cxw.studentinfo.mapper")
14 public class MybatisPlusConfig {
15     /**
16      * 配置數據源
17      */
18     @Bean
19     public DataSource dataSource(PropertyConfig propertyConfig){
20         DruidDataSource dataSource = new DruidDataSource();
21         dataSource.setUsername(propertyConfig.getUser());
22         dataSource.setPassword(propertyConfig.getPassword());
23         dataSource.setUrl(propertyConfig.getUrl());
24         dataSource.setDriverClassName(propertyConfig.getDriver());
25         return dataSource;
26     }
27 
28     /*@Bean
29     public DataSource dataSource(PropertyConfig propertyConfig) throws Exception {
30         ComboPooledDataSource dataSource = new ComboPooledDataSource();
31         dataSource.setUser(propertyConfig.getUser());
32         dataSource.setPassword(propertyConfig.getPassword());
33         dataSource.setJdbcUrl(propertyConfig.getUrl());
34         dataSource.setDriverClass(propertyConfig.getDriver());
35         return dataSource;
36     }*/
37 
38     /**
39      * 獲得getMybatisSqlSessionFactoryBean
40      * @return
41      */
42     @Bean
43     public MybatisSqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
44         MybatisSqlSessionFactoryBean mybatisPlus  = new MybatisSqlSessionFactoryBean();
45         mybatisPlus.setDataSource(dataSource);
46         return mybatisPlus;
47     }
48 
49 
50     /**
51      * 設置mapper文件的掃描路徑
52      * @return
53      */
54    /* @Bean
55     public MapperScannerConfigurer getMapperScannerConfigurer(){
56         MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
57         mapperScannerConfigurer.setBasePackage("com.cxw.studentinfo,mapper");
58         return mapperScannerConfigurer;
59     }*/
60 
61     /**
62      * 分頁插件
63      * @return
64      */
65     @Bean
66     public PaginationInterceptor getPaginationInterceptor(){
67         PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
68         //自定義方言 可以沒有
69         paginationInterceptor.setDialectType("mysql");
70         return paginationInterceptor;
71     }
72 
73 }

6、構建核心初始化文件

package com.cxw.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;


/**
 * web.xml替代文件,可以簡單理解為相web.xml文件
 */
public class WebInit extends AbstractAnnotationConfigDispatcherServletInitializer {
    //將bean加入容器
    @Override
    protected Class<?>[] getRootConfigClasses() {
        //這里可以配置需要加入容器的Bean,同樣可以聲明配置類,然后加Bean
        return new Class[]{AppConfig.class,MybatisPlusConfig.class};
    }

    //這個也是相當於將Bean加入容器
    //相當於springmvc容器
    // url映射配置,返回spring的配置文件
    //這里WebConfig主要是配置DispatcherSerlvet,視頻解析器,JSON等
    @Override
    protected Class<?>[] getServletConfigClasses() {
        //return null;
        return new Class[]{WebConfig.class};
    }
    //攔截請求匹配,只攔截/
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

四、邏輯代碼編寫

1、controller代碼

package com.cxw.studentinfo.controller;


import com.cxw.studentinfo.entity.TblStudent;
import com.cxw.studentinfo.service.ITblStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cxw
 * @since 2019-09-25
 */
@RestController
@RequestMapping("/studentinfo/tbl-student")
public class TblStudentController {
    private ITblStudentService iTblStudentService;

    @Autowired
    public TblStudentController(ITblStudentService iTblStudentService){
        this.iTblStudentService = iTblStudentService;
    }

    public TblStudentController(){

    }

    @RequestMapping("/gettblstudentbyid/{id}")
    public TblStudent getTblStudentById(@PathVariable("id") String id){
        TblStudent student = iTblStudentService.getById(id);
        return student;
    }

}

2、serivce代碼

 1 package com.cxw.studentinfo.service;
 2 
 3 import com.cxw.studentinfo.entity.TblStudent;
 4 import com.baomidou.mybatisplus.extension.service.IService;
 5 
 6 /**
 7  * <p>
 8  *  服務類
 9  * </p>
10  *
11  * @author cxw
12  * @since 2019-09-25
13  */
14 public interface ITblStudentService extends IService<TblStudent> {
15 
16 }

3、impl代碼

 
         
package com.cxw.studentinfo.service.impl;

import com.cxw.studentinfo.entity.TblStudent;
import com.cxw.studentinfo.mapper.TblStudentMapper;
import com.cxw.studentinfo.service.ITblStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* <p>
* 服務實現類
* </p>
*
* @author cxw
* @since 2019-09-25
*/
@Service
public class TblStudentServiceImpl extends ServiceImpl<TblStudentMapper, TblStudent> implements ITblStudentService {

private TblStudentMapper tblStudentMapper;

@Autowired
public TblStudentServiceImpl(TblStudentMapper tblStudentMapper){
this.tblStudentMapper = tblStudentMapper;
}

public TblStudentServiceImpl( ){

}
 
        

4、mapper代碼

 1 package com.cxw.studentinfo.mapper;
 2 
 3 import com.cxw.studentinfo.entity.TblStudent;
 4 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 5 import org.springframework.stereotype.Service;
 6 
 7 /**
 8  * <p>
 9  *  Mapper 接口
10  * </p>
11  *
12  * @author cxw
13  * @since 2019-09-25
14  */
15 @Service
16 public interface TblStudentMapper extends BaseMapper<TblStudent> {
17 
18 }

5、entity代碼

  1 package com.cxw.studentinfo.entity;
  2 
  3 import com.baomidou.mybatisplus.annotation.TableId;
  4 import java.time.LocalDateTime;
  5 import com.baomidou.mybatisplus.annotation.TableField;
  6 import java.io.Serializable;
  7 
  8 /**
  9  * <p>
 10  * 
 11  * </p>
 12  *
 13  * @author cxw
 14  * @since 2019-09-25
 15  */
 16 public class TblStudent implements Serializable {
 17 
 18     private static final long serialVersionUID = 1L;
 19 
 20     /**
 21      * 主鍵
 22      */
 23     @TableId("id")
 24     private String id;
 25 
 26     /**
 27      * 姓名
 28      */
 29     @TableField("name")
 30     private String name;
 31 
 32     /**
 33      * 年齡
 34      */
 35     @TableField("age")
 36     private String age;
 37 
 38     /**
 39      * 性別
 40      */
 41     @TableField("sex")
 42     private String sex;
 43 
 44     /**
 45      * 數據新增用戶id
 46      */
 47     @TableField("datainsuserid")
 48     private String datainsuserid;
 49 
 50     /**
 51      * 數據新增時間
 52      */
 53     @TableField("datainstime")
 54     private LocalDateTime datainstime;
 55 
 56 
 57     public String getId() {
 58         return id;
 59     }
 60 
 61     public void setId(String id) {
 62         this.id = id;
 63     }
 64 
 65     public String getName() {
 66         return name;
 67     }
 68 
 69     public void setName(String name) {
 70         this.name = name;
 71     }
 72 
 73     public String getAge() {
 74         return age;
 75     }
 76 
 77     public void setAge(String age) {
 78         this.age = age;
 79     }
 80 
 81     public String getSex() {
 82         return sex;
 83     }
 84 
 85     public void setSex(String sex) {
 86         this.sex = sex;
 87     }
 88 
 89     public String getDatainsuserid() {
 90         return datainsuserid;
 91     }
 92 
 93     public void setDatainsuserid(String datainsuserid) {
 94         this.datainsuserid = datainsuserid;
 95     }
 96 
 97     public LocalDateTime getDatainstime() {
 98         return datainstime;
 99     }
100 
101     public void setDatainstime(LocalDateTime datainstime) {
102         this.datainstime = datainstime;
103     }
104 
105     @Override
106     public String toString() {
107         return "TblStudent{" +
108         "id=" + id +
109         ", name=" + name +
110         ", age=" + age +
111         ", sex=" + sex +
112         ", datainsuserid=" + datainsuserid +
113         ", datainstime=" + datainstime +
114         "}";
115     }
116 }

6、mapper.xml代碼

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 3 <mapper namespace="com.cxw.studentinfo.mapper.TblStudentMapper">
 4 
 5     <!-- 通用查詢映射結果 -->
 6     <resultMap id="BaseResultMap" type="com.cxw.studentinfo.entity.TblStudent">
 7         <id column="id" property="id" />
 8         <result column="name" property="name" />
 9         <result column="age" property="age" />
10         <result column="sex" property="sex" />
11         <result column="datainsuserid" property="datainsuserid" />
12         <result column="datainstime" property="datainstime" />
13     </resultMap>
14 
15 </mapper>

五、測試

1、數據庫查詢結果展示

 

 

2、運行程序,訪問后結構展示

六、總結和疑問

1、使用代碼生成器的時候,如果使用的是Oracle數據庫,表名似乎需要大寫才能生成

2、配置mapper掃包的時候,如果使用非注解的形式,似乎會造成重復掃包,導致會找不到service文件

以上兩個問題是我在構建項目的時候遇到的問題

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM