python从入门到精通

第一单元 python准备

1.1 python环境的安装

1.打开网页

Welcome to Python.orgThe official home of the Python Programming Languageicon-default.png?t=O83Ahttps://www.python.org/

2.选择下载自己的系统

3.进行安装

4.测试是否安装成功

  • 打开命令管理器成功就显示版本
  • 失败就报错(没有选择add python to path)

5.手动配置python

  • 点开属性

 

  • 选择高级系统 > 环境变量 > path

  • 根据自己的路径 添加path

  • 最后在终端里面测试是否安装成功

1.2 PyCharm的下载

1.下载点击安装

2.编辑设置

1.3 PIP的使用

1.简介

pip是一个现代的,通用的python包管理工具。提供了对python包的查找,下载,安装,卸载的功能,便于我们对python的资源包进行管理。

2.安装

在安装python时,会自动下载并且安装。

3.配置

  • 在终端里面输入pip -V 可以查看pip版本。

  • 如果出现一下,再次去环境变量新建path(上文提到)

4.使用pip管理python包

  • pip install <包名>  安装指定的包
  • pip uninstall <包名>  删除指定的包
  • pip list   显示已经安装的包
  • pip freeze  显示已经安装的包,并且以指定的格式显示

5.修改pip下载源

运行pip install命令会从网站上下载指定的python包,默认从国外网站下载,速度会很慢。

格式:pip install 包名 -i 国内源地址

国内的常用pip下载源:

镜像站名    网址
阿里云开源镜像站    http://mirrors.aliyun.com/
网易开源镜像站    http://mirrors.163.com/
搜狐开源镜像    http://mirrors.sohu.com/
浙江大学开源镜像站    http://mirrors.zju.edu.cn/
清华大学开源软件镜像站    https://mirrors.tuna.tsinghua.edu.cn/
中国科学技术大学    http://mirrors.ustc.edu.cn/
腾讯开源镜像站    http://mirrors.cloud.tencent.com/pypi/simple
豆瓣开源镜像站    http://pypi.douban.com/simple/

1.4运行python程序

1.终端运行

MybatisPlus 是 Mybatis 的增强工具,可以简化 Mybatis 的开发。MybatisX 是一款 Mybatis 开发插件,可以提高 Mybatis 的开发效率。下面是 MybatisPlus+SpringBoot+MybatisX 的联合步骤: 1. 在 pom.xml 文件中添加 MybatisPlus 和 MybatisX 的依赖。 ```xml <!-- MybatisPlus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.1</version> </dependency> <!-- MybatisX --> <dependency> <groupId>io.github.mybatisx</groupId> <artifactId>mybatisx-boot-starter</artifactId> <version>2.1.0</version> </dependency> ``` 2. 配置 MybatisPlus 和 MybatisX。 ```java @Configuration public class MybatisConfig { @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } @Bean public MybatisXConfigurer mybatisXConfigurer() { return new MybatisXConfigurer(); } } ``` 3. 编写实体类和 Mapper 接口,使用 MybatisPlus 提供的注解。 ```java @Data @TableName("user") public class User { @TableId(type = IdType.AUTO) private Long id; private String username; private String password; } public interface UserMapper extends BaseMapper<User> { } ``` 4. 在 application.yml 中配置数据库连接信息和 MybatisPlus 的相关信息。 ```yaml spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: root password: root mybatis-plus: mapper-locations: classpath:/mapper/*Mapper.xml type-aliases-package: com.example.demo.entity global-config: db-config: id-type: auto field-strategy: not_null logic-delete-value: 1 logic-not-delete-value: 0 configuration: map-underscore-to-camel-case: true cache-enabled: false mybatisx: enabled: true ``` 5. 在 Controller 中使用 Mapper 接口进行数据库操作。 ```java @RestController public class UserController { @Autowired private UserMapper userMapper; @GetMapping("/user/{id}") public User getUser(@PathVariable("id") Long id) { return userMapper.selectById(id); } @PostMapping("/user") public boolean addUser(@RequestBody User user) { return userMapper.insert(user) > 0; } @PutMapping("/user") public boolean updateUser(@RequestBody User user) { return userMapper.updateById(user) > 0; } @DeleteMapping("/user/{id}") public boolean deleteUser(@PathVariable("id") Long id) { return userMapper.deleteById(id) > 0; } } ``` 这样,就完成了 MybatisPlus+SpringBoot+MybatisX 的整合。在 Controller 中,可以直接注入 Mapper 接口进行数据库操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值