application.ymlorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testtest org.springframework.boot spring-boot-starter-weborg.mybatis.spring.boot mybatis-spring-boot-starter2.1.3 com.github.pagehelper pagehelper5.1.2 mysql mysql-connector-javacom.alibaba druid1.1.22 com.alibaba fastjson1.2.47 org.springframework.boot spring-boot-devtoolsruntime true org.springframework.boot spring-boot-starter-thymeleafnet.sourceforge.nekohtml nekohtml1.9.22 org.projectlombok lombok
#修改端口号
server:
port: 8080
servlet:
encoding:
charset: UTF-8
force: true
enabled: true
tomcat:
uri-encoding: UTF-8 # tomcat的URI编码
#数据库
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
username: root
password: 123456
url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
#配置静态资源
web:
resources:
static-locations: classpath:/static/,classpath:/templates/
mybatis:
#别名
type-aliases-package: com.yzx.boot.entity
#xml配置
mapper-locations: classpath:mybatis
private Integer id;
private String name;
private Integer age;
private Double salary;
}
mapper层:
package com.yzx.boot.mapper;
import com.yzx.boot.entity.Emp;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface EmpMapper {
// List login(Emp emp);
List find(Emp emp);
int del(Integer id);
Emp findByID(Integer id);
int upd(Emp emp);
int add(Emp emp);
}
service层:
package com.yzx.boot.service.user;
import com.yzx.boot.entity.Emp;
import com.yzx.boot.entity.Userinfo;
import java.util.List;
public interface EmpService {
// Emp login(Emp emp);
List find(Emp emp);
int del(Integer id);
Emp findByID(Integer id);
int upd(Emp emp);
int add(Emp emp);
}
serviceimpl:
package com.yzx.boot.service.user;
import com.yzx.boot.entity.Emp;
import com.yzx.boot.mapper.EmpMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class EmpServiceimpl implements EmpService {
@Resource
private EmpMapper empmapper;
// @Override
// public Emp login(Emp emp) {
// List list = empmapper.login(emp);
// if (list != null && list.size() > 0) {
// return list.get(0);
// }
// return null;
// }
@Override
public List find(Emp emp) {
return empmapper.find(emp);
}
@Override
public int del(Integer id) {
return empmapper.del(id);
}
@Override
public Emp findByID(Integer id) {
return empmapper.findByID(id);
}
@Override
public int upd(Emp emp) {
return empmapper.upd(emp);
}
@Override
public int add(Emp emp) {
System.out.println(emp);
return empmapper.add(emp);
}
}
前台代码:html
{{msg}}
编号 姓名 年龄 工资 操作 {{it.id}} {{it.name}} {{it.age}} {{it.salary}}
姓名:
年龄:
工资:



