Git Tips
Q7nl1s admin

EN

Use -b to specify a branch when cloning a repository

To clone the master branch:

1
git clone -b master https://github.com/xiwuqi/automobile.git

To clone the develop branch:

1
git clone -b develop https://github.com/xiwuqi/automobile.git

Project renaming reference: springboot-Modify Project Name_springboot_modify project name_qq_41665356’s blog-CSDN blog

From 2021.8.13, Github requires token-based authentication - Zhihu (zhihu.com)

After generating your token, log in and paste the token in the password input field.

If there is no prompt for password input during push and other operations, run the following command to see the password prompt:

1
git config --system --unset credential.helper

You can directly add the token to the remote repository URL to avoid entering the token each time you commit to the same repository:

1
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
  • <your_token>: Replace with your generated token
  • <USERNAME>: Your GitHub username
  • <REPO>: Your repository name

Force push:

1
git push origin develop -f

Pitfalls in renaming a module in a Spring Boot project

Step 1: Refactor -> Rename -> Rename module and directory

image-20230424111942386

Step 2: Modify the pom.xml file

This is the pom.xml file of the renamed module

image-20230424112220068

If it is included under a parent module, you need to modify the parent pom.xml file as well.

Step 3: Maven related

image-20230424112540795

Most important:

image-20230424112629360

After this step, you will see dependency files under the relevant module in Project Structure. ==If the previous step is skipped, the dependencies here will be empty==

image-20230424112801978

image-20230424112930823

Issues with auto-injection

Regarding these component annotations, the key point is that the following four annotations have the same effect, all injecting into the container. However, it’s best to follow conventions within different package names:

1
2
3
4
5
6
7
@Repository: For the DAO layer

@Component: Commonly used for entity layers

@Service: For the service layer

@Controller: For the Controller

Using these annotations, @Autowired will not throw an error saying it cannot find the bean. These four annotations all serve the same function: they register a class into Spring and inject it into a Bean.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@RestController
@RequestMapping(value = "/user")
public class UserController {

@Autowired
UserService userService;

// Login
@RequestMapping(value = "/login")
public Map<String, Object> login(@RequestBody User user) {
// Login
User userObj = userService.login(user);
if(userObj == null) { // Incorrect username or password
// Return result object
return ...

In the code above, the @Autowired annotation will automatically inject the userService. Spring will automatically scan all classes annotated with @Repository, @Service, and @Controller, and register them as beans.

It is important to note that the @Service annotation is used to mark implementation classes, not interfaces.

You need to create a class that implements the UserService interface and annotate the class with @Service.

For example:

1
2
3
4
5
@Service
public class UserServiceImpl implements UserService {
// Implement methods from the interface
// ...
}

For the same interface UserMapper, if you use the MyBatis framework to interact with the database and use MapperScannerConfigurer or MapperScan annotations to automatically scan Mapper interfaces, you can add the @Mapper annotation to the UserMapper class to register it as a bean.

Checking port usage and killing the corresponding process on macOS

To check port usage on a Mac, you can use lsof followed by the port number, for example, to check port 8080:

1
lsof -i tcp:8080

image-20230424150938080

You can use kill with the -9 parameter to force stop a process, followed by the PID. To stop the above process, use the following command:

1
kill -9 2689

image-20230424151033703

Adding the README file to the local Git repository

Use the following command:

1
git add README.md

Commit the changes and push them to the remote repository. When committing, you need to provide a commit message to inform other developers of the changes you made. Use the following commands:

1
2
3
git commit -m "Add README.md"
git remote add origin <remote repository URL>
git push -u origin master

MyBatis automatic code generation for GeneratorMapper.xml

Previously missed MyBatis automatic code generation-GeneratorMapper.xml configuration_Beginner’s blog-CSDN blog

MyBatis automatic code generation using GeneratorMapper file - Juejin (juejin.cn)

image-20230426132144452

Mine is:

1
/Users/wuxi/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- Specify the location of the JDBC driver for connecting to the database, set the full path on your machine -->
<classPathEntry location="/Users/wuxi/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar"/>
<!-- Configure table information content body, targetRuntime specifies using MyBatis3 version -->
<context id="tables" targetRuntime="MyBatis3">
<!-- Suppress generating comments, as they are all in English and can be omitted -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- Configure database connection information -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/auto_display"
userId="root"
password="9517538426">
</jdbcConnection>
<!-- Generate model classes, targetPackage specifies the package name for model classes
targetProject specifies the Eclipse project where the generated model will be placed -->
<javaModelGenerator targetPackage="com.wuxi.ads.bean"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="false"/>
</javaModelGenerator>
<!-- Generate MyBatis Mapper.xml file, targetPackage specifies the package name for the mapper.xml file,
targetProject specifies the Eclipse project where the generated mapper.xml will be placed -->
<sqlMapGenerator targetPackage="com.wuxi.ads.mapper"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- Generate MyBatis Mapper interface class file, targetPackage specifies the package name for the Mapper interface class,
targetProject specifies the Eclipse project where the generated Mapper interface will be placed -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.wangpeng.bms.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>

<!-- Database table name and corresponding Java model class

name -->
<table tableName="car_brand" domainObjectName="CarBrand"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>

For detailed configuration generation process, see: MyBatis automatic code generation-GeneratorMapper.xml configuration_Beginner’s blog-CSDN blog

image-20230426134027479

Reference: IDEA does not display Maven plugin mybatis-generator solution_dadeity’s blog-CSDN blog

Automatically generate entity classes, Mapper, and Mapper.xml files based on database tables through GeneratorMapper.xml

image-20230426194146409

Solution for Permission denied error in sh files

Generally, this happens with projects that have been run before and already have a node_modules folder. Delete it and run node install again.

image-20230426202226950

Node version issues when switching between Windows and Mac

1
2
3
4
5
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@achrinza/node-ipc@9.2.2',
npm WARN EBADENGINE required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
npm WARN EBADENGINE current: { node: 'v18.14.2', npm: '9.5.0' }
npm WARN EBADENGINE }

image-20230426202430223

Modify the configuration in package-lock.json as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
"node_modules/@achrinza/node-ipc": {
"version": "9.2.2",
"resolved": "https://registry.npmmirror.com/@achrinza/node-ipc/-/node-ipc-9.2.2.tgz",
"integrity": "sha512-b90U39dx0cU6emsOvy5hxU4ApNXnE3+Tuo8XQZfiKTGelDwpMwBVgBP7QX6dGTcJgu/miyJuNJ/2naFBliNWEw==",
"dev": true,
"dependencies": {
"@node-ipc/js-queue": "2.0.3",
"event-pubsub": "4.3.0",
"js-message": "1.0.7"
},
"engines": {
"node": "8 || 10 || 12 || 14 || 16 || 17 || 18"
}
},

Add 18

Error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wuxi.ads.mapper.UserMapper.selectByUsernameAndPasswordAndRole
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:232) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:50) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62) ~[mybatis-3.5.0.jar:3.5.0]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_362]
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57) ~[mybatis-3.5.0.jar:3.5.0]
at com.sun.proxy.$Proxy69.selectByUsernameAndPasswordAndRole(Unknown Source) ~[na:na]
at com.wuxi.ads.service.impl.UserServiceImpl.login(UserServiceImpl.java:25) ~[classes/:na]
at com.wuxi.ads.controller.UserController.login(UserController.java:26) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_362]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_362]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_362]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_362]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.24.jar:5.3.24]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) ~[tomcat-embed-core-9.0.69.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.24.jar:5.3.24]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:779) ~[tomcat-embed-core-9.0.69.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.24.jar:5.3.24]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.24.jar:5.3.24]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.24.jar:5.3.24]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:891) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.69.jar:9.0.69]
at java.lang.Thread.run(Thread.java:750) [na:1.8.0_362]

Notes on Database Field Naming

In MySQL, role is a reserved word, so you need to be extra careful when using role as a column name or table name. If you use role as a column name, you need to enclose it in backticks (`) so that MySQL can correctly parse it:

1
SELECT `role` FROM mytable;

Using reserved words as column names in queries usually results in syntax errors. Therefore, it is best to avoid using reserved words as column names or table names to prevent unexpected errors.




CN

使用 git 拉代码时可以使用 -b 指定分支

指定拉 master 分支代码

1
git clone -b master https://github.com/xiwuqi/automobile.git

指定拉 develop 分支代码

1
git clone -b develop https://github.com/xiwuqi/automobile.git

项目改名参考springboot-修改项目名_springboot修改项目名称_qq_41665356的博客-CSDN博客

2021.8.13起,Github要求使用基于令牌的身份验证 - 知乎 (zhihu.com)

之后用自己生成的token登录,把上面生成的token粘贴到输入密码的位置。

如果 push 等操作没有出现输入密码选项,请先输入如下命令,之后就可以看到输入密码选项了。

1
git config --system --unset credential.helper

把token直接添加远程仓库链接中,这样就可以避免同一个仓库每次提交代码都要输入token了:

1
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
  • <your_token>:换成你自己得到的token
  • <USERNAME>:是你自己github的用户名
  • <REPO>:是你的仓库名称

强制推送

1
git push origin develop -f

给springboot项目重命名module的坑

第一步 refactor->rename->rename module and directory

image-20230424111942386

第二步修改 pom.xml 文件

这是当前重命名的 moudule 的 pom.xml 文件

image-20230424112220068

如果其包含在父 module 下,则需要把上级的 pom.xml 一并修改

第三步 meaven 相关

image-20230424112540795

最最重要

image-20230424112629360

下完之后就可以在 Project Structure 的相关 module 下看到依赖文件了 ==如果没有上一步,此处的依赖项是空的==

image-20230424112801978

image-20230424112930823

自动注入相关问题

关于这类组件注解
关键点来了下面这四点实际上效果是一样的都是注入到容器中,不过在不同的包名内最好按规范来写:

1
2
3
4
5
6
7
@Repository:代表dao层

@Component:这个惯用实体层

@Service : 这个用于service层

@Controller : 这个用于Controller

配上以上注解自自动装配时 @Autowired 才不会报找不到错误
这四个注解的功能都是一样的,都是代表某个类注册到 Spring 中,装配到 Bean 中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@RestController
@RequestMapping(value = "/user")
public class UserController {

@Autowired
UserService userService;

// 登录
@RequestMapping(value = "/login")
public Map<String, Object> login(@RequestBody User user) {
// 登录
User userObj = userService.login(user);
if(userObj == null) { // 账号或密码错误
// 返回结果对象
return ...

上面代码中的 @Autowired 注解将自动为 userService 进行注入,Spring 会自动扫描所有使用 @Repository@Service@Controller 注解的类,并将它们注册为 bean。

值得注意的是 @Service 注解是用来标识 实现类 的,而不是接口。

你需要创建一个实现 UserService 接口的类,并在类上加上 @Service 注解。

比如:

1
2
3
4
5
@Service
public class UserServiceImpl implements UserService {
// 实现接口中的方法
// ...
}

对于同样的接口 UserMapper 如果你使用 MyBatis 框架来操作数据库,并且使用了 MapperScannerConfigurer 或 MapperScan 注解来自动扫描 Mapper 接口,那么你可以在 UserMapper 类上添加@Mapper 注解,将其注册为 bean。

mac 查看端口号占用情况并利用 PID kill 掉相应进程

Mac上查看端口号占用可以使用 lsof,然后跟上对应的端口,比如要查 8080 占用的情况:

1
lsof -i tcp:8080

image-20230424150938080

kill 可以加上 -9 参数强制停止,后面跟的是 PID,停止上面进程方式如下:

1
kill -9 2689

image-20230424151033703

将README文件添加到本地Git仓库中,使用以下命令:

1
2
csharpCopy code
$ git add README.md

提交更改并将其推送到远程存储库。在提交时,您需要提供一些提交信息,以便其他开发人员了解您所做的更改。使用以下命令:

1
2
3
4
rubyCopy code
$ git commit -m "Add README.md"
$ git remote add origin <remote repository URL>
$ git push -u origin master

Mybatis自动生成代码GeneratorMapper.xml

之前漏掉的Mybatis自动生成代码-GeneratorMapper.xml配置_初级使用者的博客-CSDN博客

Mybatis自动代码生成之GeneratorMapper文件的使用 - 掘金 (juejin.cn)

image-20230426132144452

我的为

1
/Users/wuxi/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 指定连接数据库的 JDBC 驱动包所在位置,指定到你本机的完整路径 -->
<classPathEntry location="/Users/wuxi/.m2/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar"/>
<!-- 配置 table 表信息内容体,targetRuntime 指定采用 MyBatis3 的版本 -->
<context id="tables" targetRuntime="MyBatis3">
<!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 配置数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/auto_display"
userId="root"
password="9517538426">
</jdbcConnection>
<!-- 生成 model 类,targetPackage 指定 model 类的包名
targetProject 指定生成的 model 放在 eclipse 的哪个工程下面-->
<javaModelGenerator targetPackage="com.wuxi.ads.bean"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="false"/>
</javaModelGenerator>
<!-- 生成 MyBatis 的 Mapper.xml 文件,targetPackage 指定 mapper.xml 文件的
包名, targetProject 指定生成的 mapper.xml 放在 eclipse 的哪个工程下面 -->
<sqlMapGenerator targetPackage="com.wuxi.ads.mapper"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- 生成 MyBatis 的 Mapper 接口类文件,targetPackage 指定 Mapper 接口类的包
名, targetProject 指定生成的 Mapper 接口放在 eclipse 的哪个工程下面 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.wangpeng.bms.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>

<!-- 数据库表名及对应的 Java 模型类名 -->
<table tableName="car_brand" domainObjectName="CarBrand"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>

具体配置生成过程参见:Mybatis自动生成代码-GeneratorMapper.xml配置_初级使用者的博客-CSDN博客

image-20230426134027479

参考:IDEA 不显示 Maven 插件 mybatis-generator 解决_dadeity的博客-CSDN博客

通过 GeneratorMapper.xml 自动根据数据库表生成实体类、Mapper 和 *Mapper.xml 文件

image-20230426194146409

sh文件出现错误:Permission denied 解决办法

一般都是直接拿的别人运行过的项目,已经存在 node_modules 文件夹,把它删了重新 node install 就好了

image-20230426202226950

windows mac 切换时 node 版本问题

1
2
3
4
5
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@achrinza/node-ipc@9.2.2',
npm WARN EBADENGINE required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
npm WARN EBADENGINE current: { node: 'v18.14.2', npm: '9.5.0' }
npm WARN EBADENGINE }

image-20230426202430223

package-lock.json 修改配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
"node_modules/@achrinza/node-ipc": {
"version": "9.2.2",
"resolved": "https://registry.npmmirror.com/@achrinza/node-ipc/-/node-ipc-9.2.2.tgz",
"integrity": "sha512-b90U39dx0cU6emsOvy5hxU4ApNXnE3+Tuo8XQZfiKTGelDwpMwBVgBP7QX6dGTcJgu/miyJuNJ/2naFBliNWEw==",
"dev": true,
"dependencies": {
"@node-ipc/js-queue": "2.0.3",
"event-pubsub": "4.3.0",
"js-message": "1.0.7"
},
"engines": {
"node": "8 || 10 || 12 || 14 || 16 || 17 || 18"
}
},

即加上18

报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wuxi.ads.mapper.UserMapper.selectByUsernameAndPasswordAndRole
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:232) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:50) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62) ~[mybatis-3.5.0.jar:3.5.0]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_362]
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62) ~[mybatis-3.5.0.jar:3.5.0]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57) ~[mybatis-3.5.0.jar:3.5.0]
at com.sun.proxy.$Proxy69.selectByUsernameAndPasswordAndRole(Unknown Source) ~[na:na]
at com.wuxi.ads.service.impl.UserServiceImpl.login(UserServiceImpl.java:25) ~[classes/:na]
at com.wuxi.ads.controller.UserController.login(UserController.java:26) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_362]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_362]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_362]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_362]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.24.jar:5.3.24]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.24.jar:5.3.24]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) ~[tomcat-embed-core-9.0.69.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.24.jar:5.3.24]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:779) ~[tomcat-embed-core-9.0.69.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.24.jar:5.3.24]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.24.jar:5.3.24]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.24.jar:5.3.24]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.24.jar:5.3.24]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177) ~[tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:891) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.69.jar:9.0.69]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.69.jar:9.0.69]
at java.lang.Thread.run(Thread.java:750) [na:1.8.0_362]

数据库字段命名注意事项

在 MySQL 中,role是一个保留字,因此在使用role作为列名或表名时需要格外小心。如果您将role作为列名,您需要用反引号(`)来将其括起来,以便 MySQL 正确解析:

1
SELECT `role` FROM mytable;

在查询中使用保留字作为列名通常会导致语法错误。因此,最好避免将保留字用作列名或表名,以免出现意外错误。

 Comments
Comment plugin failed to load
Loading comment plugin
Powered by Hexo & Theme Keep
Unique Visitor Page View