打开IDEA,进入 File -> Settings -> Plugins -> Browse Repositories,输入MybatisX 搜索并安装,安装完成后 IDEA 会提示需要重启。
配置数据库
我的表
路径:要在后面再加模块名:ssm,我的是这样的
我的
这里选3
刷新
注意选择3
pom.xml文件
4.0.0
com.shop
ssm-project
war
1.0-SNAPSHOT
ssm-project Maven Webapp
http://www.example.com
UTF-8
1.8
1.8
junit
junit
4.12-beta-3
test
org.springframework
spring-core
5.2.0.RELEASE
org.springframework
spring-beans
5.2.0.RELEASE
org.springframework
spring-context
5.2.0.RELEASE
org.springframework
spring-test
5.2.0.RELEASE
org.springframework
spring-aop
5.2.0.RELEASE
org.springframework
spring-tx
5.2.0.RELEASE
org.springframework
spring-web
5.2.0.RELEASE
org.springframework
spring-webmvc
5.2.0.RELEASE
org.springframework
spring-jdbc
5.2.0.RELEASE
mysql
mysql-connector-java
8.0.22
org.apache.commons
commons-dbcp2
2.5.0
org.mybatis
mybatis
3.5.3
org.slf4j
slf4j-api
1.7.25
org.slf4j
slf4j-log4j12
1.7.10
org.apache.logging.log4j
log4j-api
2.10.0
org.apache.logging.log4j
log4j-core
2.10.0
org.apache.logging.log4j
log4j-web
2.9.1
org.mybatis
mybatis-spring
2.0.3
javax.servlet
javax.servlet-api
3.1.0
provided
javax.servlet
jstl
1.2
org.projectlombok
lombok
1.18.20
com.github.pagehelper
pagehelper
5.0.0
commons-fileupload
commons-fileupload
1.3.1
commons-io
commons-io
2.4
com.google.code.gson
gson
2.8.8
com.alibaba
fastjson
1.2.28
com.fasterxml.jackson.core
jackson-core
2.9.5
com.fasterxml.jackson.core
jackson-databind
2.9.5
com.fasterxml.jackson.core
jackson-annotations
2.9.5
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
2.9.5
com.baomidou
mybatis-plus-annotation
3.4.2
com.baomidou
mybatis-plus-extension
3.4.2
ssm-project
spring.xml
reasonable=true
springmvc.xml
application/json;charset=utf-8
text/html;charset=utf-8
application/json; charset=UTF-8
application/x-www-form-urlencoded; charset=UTF-8
5097152
web.xml
Archetype Created Web Application
contextConfigLocation
classpath*:spring*.xml
org.springframework.web.context.ContextLoaderListener
DispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
DispatcherServlet
/
CORS
com.shop.util.CORSFilter
CORS
/*
db.properties
jdbc.username=root
jdbc.password=111111
jdbc.url=jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
jdbc.driverClassName=com.mysql.cj.jdbc.Driver
log4j.properties(暂时用这个)
# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# MyBatis logging configuration...
log4j.logger.com.shop.mapper.ManagerMapper=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
Controller.java
package com.shop.web;
import com.shop.entity.Manager;
import com.shop.result.Meta;
import com.shop.result.MyConstant;
import com.shop.result.ResultInfo;
import com.shop.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 作者 汤永红
* 日期 2023/8/15 15:19
* 公司 HR
* 实实在在敲代码
*/
@Controller
@RequestMapping("/api/private/v1/")
public class ManagerController {
@Autowired
private ManagerService managerService;
@PostMapping("/login")
@ResponseBody
public ResultInfo login(String username, String password) {
//登陆
Manager manager = managerService.login(username, password);
ResultInfo resultInfo = new ResultInfo();
Meta meta = new Meta();
if (manager != null) {
meta.setStatus(MyConstant.OK);
meta.setMsg(MyConstant.OK_MSG);
} else {
meta.setStatus(MyConstant.NOT_FOUND_DATA);
meta.setMsg(MyConstant.NOT_FOUND_DATA_MSG);
}
resultInfo.setMeta(meta);
resultInfo.setData(manager);
return resultInfo;
}
}