您的位置:首页 > 财经 > 金融 > 海口制作网站软件_企业门户网站管理办法_新网站应该怎么做seo_一键seo提交收录

海口制作网站软件_企业门户网站管理办法_新网站应该怎么做seo_一键seo提交收录

2025/3/11 15:04:42 来源:https://blog.csdn.net/kong7906928/article/details/143464714  浏览:    关键词:海口制作网站软件_企业门户网站管理办法_新网站应该怎么做seo_一键seo提交收录
海口制作网站软件_企业门户网站管理办法_新网站应该怎么做seo_一键seo提交收录

一、字段映射与表名映射

数据库表和实体类名称一样自动关联,数据库表和实体类有部分情况不一样。

问题一:表名与编码开发设计不同步,表名和实体类名称不一致。

 解决办法:   

在模型类上方,使用@TableName注解,通过value属性,设置当前类对应的数据库表名称。

示例代码如下:

package com.it.domain;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;//lombok
@Data
@TableName("tbl_user")//
public class User {private Long id;private String name;@TableField(value = "pwd",select = false)private String password;private Integer age;private String tel;@TableField(exist = false)private Integer online;
}

 问题二:表字段与编码属性设计不同步

 解决办法:   

    在模型类属性上方,使用@TableField属性注解,通过value属性,设置当前属性对应的数据库表中的字段关系。

示例代码:

package com.it.domain;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;//lombok
@Data
@TableName("tbl_user")//
public class User {private Long id;private String name;@TableField(value = "pwd",select = false)private String password;private Integer age;private String tel;@TableField(exist = false)private Integer online;
}


 问题三:编码中添加了数据库中未定义的属性
 
 在User实体类中定义了 是否在线属性。

解决办法:

        在模型类属性上方,使用@TableField注解,通过exist属性,设置属性在数据库表字段中是否存在,默认为true。此属性无法与value合并使用。

示例代码:

package com.it.domain;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;//lombok
@Data
@TableName("tbl_user")//
public class User {private Long id;private String name;@TableField(value = "pwd",select = false)private String password;private Integer age;private String tel;@TableField(exist = false)private Integer online;
}

问题四:采用默认查询开放了更多的字段查看权限

用字段列表查询,列出字段,带有索引往前排,不带索引的往后排,查询效率有一定提升。

     解决办法:   

        在模型类属性上方,使用@TableField注解,通过select属性:设置该属性是否参与查询。此属性与select()映射配置不冲突。

示例代码:

package com.it.domain;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;//lombok
@Data
@TableName("tbl_user")//
public class User {private Long id;private String name;@TableField(value = "pwd",select = false)private String password;private Integer age;private String tel;@TableField(exist = false)private Integer online;
}

单元测试代码:

package com.it;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;...@SpringBootTest
class Mybatisplus02DqlApplicationTests {@Autowiredprivate UserDao userDao;@Testvoid testGetAll() {LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<User>();List<User> userList = userDao.selectList(lqw);System.out.println(userList);}}

经过测试,字段名与表名映射成功。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com