public class Test {
public static void main(String[] args) throws Exception{
List warnings = new ArrayList();
boolean overwrite = true;
File configFile = new File("gertor.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
}
deptId, deptName
select
from tbl_dept
where deptId = #{deptid,jdbcType=INTEGER}
select from tbl_dept
delete from tbl_dept
where deptId = #{deptid,jdbcType=INTEGER}
insert into tbl_dept (deptId, deptName)
values (#{deptid,jdbcType=INTEGER}, #{deptname,jdbcType=VARCHAR})
insert into tbl_dept
deptId,
deptName,
#{deptid,jdbcType=INTEGER},
#{deptname,jdbcType=VARCHAR},
update tbl_dept
deptName = #{deptname,jdbcType=VARCHAR},
where deptId = #{deptid,jdbcType=INTEGER}
update tbl_dept
set deptName = #{deptname,jdbcType=VARCHAR}
where deptId = #{deptid,jdbcType=INTEGER}
TableLayui类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TableLayui {
private Integer code;
private String msg;
private Long count;
private Object data;
}
Reust类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Reust {
Integer code;
String msg;
Object data;
}
Emp类
package com.cheng.entity;
public class Emp {
private Integer empid;
private String empname;
private String gender;
private String email;
private Integer dId;
private Dept dept;
public Dept getDept() {
return dept;
}
public void setDept(Dept dept) {
this.dept = dept;
}
public Integer getEmpid() {
return empid;
}
public void setEmpid(Integer empid) {
this.empid = empid;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname == null ? null : empname.trim();
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender == null ? null : gender.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public Integer getdId() {
return dId;
}
public void setdId(Integer dId) {
this.dId = dId;
}
}
dept类
package com.cheng.entity;
public class Dept {
private Integer deptid;
private String deptname;
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public String getDeptname() {
return deptname;
}
public void setDeptname(String deptname) {
this.deptname = deptname == null ? null : deptname.trim();
}
}
EmpMapper
package com.cheng.dao;
import com.cheng.entity.Emp;
import java.util.List;
public interface EmpMapper {
int deleteByPrimaryKey(Integer empid);
int insert(Emp record);
int insertSelective(Emp record);
Emp selectByPrimaryKey(Integer empid);
int updateByPrimaryKeySelective(Emp record);
int updateByPrimaryKey(Emp record);
// 查询emp所有
List findAllEmp();
// 删除信息
int del(Integer empid);
// 修改添加
int ap(Emp emp);
}
DeptMapper
package com.cheng.dao;
import com.cheng.entity.Dept;
import java.util.List;
public interface DeptMapper {
int deleteByPrimaryKey(Integer deptid);
int insert(Dept record);
int insertSelective(Dept record);
Dept selectByPrimaryKey(Integer deptid);
int updateByPrimaryKeySelective(Dept record);
int updateByPrimaryKey(Dept record);
List selectAll();
}
EmpController
package com.cheng.controller;
import com.cheng.dao.EmpMapper;
import com.cheng.entity.Emp;
import com.cheng.util.Reust;
import com.cheng.util.TableLayui;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class EmpController {
@Autowired
private EmpMapper empMapper;
@RequestMapping("findAllEmp")
public TableLayui findAllEmp(Integer page, Integer limit) {
PageHelper.startPage(page, limit);
List list = empMapper.findAllEmp();
PageInfo pageInfo = new PageInfo(list);
return new TableLayui(0, "", pageInfo.getTotal(), pageInfo.getList());
}
//
@RequestMapping("svae")
public Reust svae(Emp emp) {
int ap;
if (emp.getEmpid() != null && emp.getEmpid() != 0) {
ap = empMapper.updateByPrimaryKey(emp);
} else {
ap = empMapper.insert(emp);
}
if (ap>0) {
return new Reust(200, "添加成功", null);
}else {
return new Reust(500, "添加失败", null);
}
}
// 删除
@RequestMapping("del")
public Reust del(Integer empId) {
int del = empMapper.del(empId);
// System.out.println(empId);
if (del > 0) {
return new Reust(200, "删除成功", null);
} else {
return new Reust(200, "删除成功", null);
}
}
//
@RequestMapping("cname")
public Reust cname(String empname) {
if (empname.equals("ccr")){
return new Reust(200,"账号存在",null);
}else {
return new Reust(500,"账号失败",null);
}
}
}
Deptcontertller
package com.cheng.controller;
import com.cheng.dao.DeptMapper;
import com.cheng.entity.Dept;
import com.cheng.util.Reust;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class Deptcontertller {
@Autowired
private DeptMapper deptMapper;
@RequestMapping("/findById")
@ResponseBody
public Dept findByid(Integer id){
Dept dept = deptMapper.selectByPrimaryKey(id);
return dept;
}
@RequestMapping("getByDept")
@ResponseBody
public Reust getByDept(){
List depts = deptMapper.selectAll();
return new Reust(200,"查询成功",depts);
}
}