IDEA基本设置 : https://blog.csdn.net/weixin_40816738/article/details/90116150.
IDEA中已配置阿里镜像,但maven无法下载jar包的问题 https://blog.csdn.net/redhat0921/article/details/104969687.
最新Maven阿里云仓库配置【亲测有效】
: https://www.cnblogs.com/JaxYoun/p/12699291.html.
IDEA每次建新项目都要重新配置maven的设置 https://www.cnblogs.com/Marydon20170307/p/13277870.html?utm_source=tuicool.
目前有四个子模块:web、service、dao、entity
依赖关系是:
<parent>
<artifactId>zmartifactId>
<groupId>org.examplegroupId>
<version>1.0-SNAPSHOTversion>
parent>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}groupId>
<artifactId>serviceartifactId>
<version>${project.parent.version}version>
dependency>
dependencies>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}groupId>
<artifactId>daoartifactId>
<version>${project.parent.version}version>
dependency>
dependencies>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}groupId>
<artifactId>entityartifactId>
<version>${project.parent.version}version>
dependency>
dependencies>
<dependencies>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<optional>trueoptional>
dependency>
dependencies>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.3.4.RELEASEversion>
<relativePath/>
parent>
package com.zm.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
private Integer id;
private String name;
private Integer age;
private String skill;
private String evaluate;
private Integer fraction;
}
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<scope>runtimescope>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>2.1.1version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>1.1.6version>
dependency>
package com.zm.dao;
import com.zm.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface UserDao {
User selectUserInfoByName(String name);
}
UserDao.mxl
<mapper namespace="com.zm.dao.UserDao">
<resultMap id="BaseResultMap" type="com.zm.entity.User">
<result column="id" property="id"/>
<result column="name" property="name"/>
<result column="age" property="age"/>
<result column="skill" property="skill"/>
<result column="evaluate" property="evaluate"/>
<result column="fraction" property="fraction"/>
resultMap>
<select id="selectUserInfoByName" resultMap="BaseResultMap">
SELECT * FROM user_info WHERE name = #{name}
select>
mapper>
package com.zm.service;
import com.zm.entity.User;
public interface UserService {
User selectUserInfoByName(String name);
}
package com.zm.service.impl;
import com.zm.dao.UserDao;
import com.zm.entity.User;
import com.zm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User selectUserInfoByName(String name) {
return userDao.selectUserInfoByName(name);
}
}
server:
port: 8080
spring:
datasource:
username: root
password: root
#?serverTimezone=UTC解决时区的报错
url: jdbc:mysql://localhost:3306/user?serverTimezone=UTC&useUnicode=true&charactUserDao.xmlerEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
#Spring Boot 默认是不注入这些属性值的,需要自己绑定
#druid 数据源专有配置
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
#配置监控统计拦截的filters,stat:监控统计、log4j:日志记录、wall:防御sql注入
#如果允许时报错 java.lang.ClassNotFoundException: org.apache.log4j.Priority
#则导入 log4j 依赖即可,Maven 地址:https://mvnrepository.com/artifact/log4j/log4j
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
mybatis:
# xml扫描,多个目录用逗号或者分号分隔(告诉 Mapper 所对应的 XML 文件位置)
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.zm.entity
package com.zm.web;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = "com.zm")
@MapperScan("com.zm.dao")
public class WebApplication {
public static void main(String[] args) {
SpringApplication.run(WebApplication.class, args);
}
}
<build>
<resources>
<resource>
<directory>src/main/javadirectory>
<includes>
<include>**/*.ymlinclude>
<include>**/*.propertiesinclude>
<include>**/*.xmlinclude>
includes>
<filtering>truefiltering>
resource>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.ymlinclude>
<include>**/*.propertiesinclude>
<include>**/*.xmlinclude>
includes>
<filtering>falsefiltering>
resource>
resources>
build>
Date: 2020-09-26 12:01:31
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `user_info`
-- ----------------------------
DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(32) DEFAULT NULL COMMENT '姓名',
`age` int(11) DEFAULT NULL COMMENT '年龄',
`skill` varchar(32) DEFAULT NULL COMMENT '技能',
`evaluate` varchar(64) DEFAULT NULL COMMENT '评价',
`fraction` bigint(11) DEFAULT NULL COMMENT '分数',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表';
-- ----------------------------
-- Records of user_info
-- ----------------------------
INSERT INTO `user_info` VALUES ('1', '小明', '20', '画画', '该学生在画画方面有一定天赋', '89');
INSERT INTO `user_info` VALUES ('2', '小兰', '19', '游戏', '近期该学生由于游戏的原因导致分数降低了', '64');
INSERT INTO `user_info` VALUES ('3', '张张', '18', '英语', '近期该学生参加英语比赛获得二等奖', '90');
INSERT INTO `user_info` VALUES ('4', '大黄', '20', '体育', '该学生近期由于参加篮球比赛,导致脚伤', '76');
INSERT INTO `user_info` VALUES ('5', '大白', '17', '绘画', '该学生参加美术大赛获得三等奖', '77');
INSERT INTO `user_info` VALUES ('7', '小龙', '18', 'JAVA', '该学生是一个在改BUG的码农', '59');