idea里面 file---new-project
Server url
目录结构
数据库链接项目配置
application.yml
yaml
server:
port: 8888
spring:
datasource:
url: jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=UTF-8
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
主要目录
controller
service
impl实现类
model
mapper
java接口详细描述
创建文件顺序
model---Role
mapper---RoleMapper 继承Role
service----IRoleService 继承Role
service(impl)---RoleServiceImpl 实现IRoleService
controller---RoleController 实现接口返回前端
model---Role
java
// model---Role
package com.xiaolibao.javacxyxiaolibao.model;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@TableName("role_info")
@Data
public class Role {
private String id;
private String name;
private String phone;
}
mapper---RoleMapper
java
// mapper---RoleMapper
package com.xiaolibao.javacxyxiaolibao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaolibao.javacxyxiaolibao.model.Role;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface RoleMapper extends BaseMapper<Role> {
}
service----IRoleService
java
// service----IRoleService 继承Role
package com.xiaolibao.javacxyxiaolibao.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xiaolibao.javacxyxiaolibao.model.Role;
import java.util.List;
public interface IRoleService extends IService<Role> {
List<Role> test();
}
impl--- RoleServiceImpl
java
// RoleServiceImpl 实现IRoleService
package com.xiaolibao.javacxyxiaolibao.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaolibao.javacxyxiaolibao.mapper.RoleMapper;
import com.xiaolibao.javacxyxiaolibao.model.Role;
import com.xiaolibao.javacxyxiaolibao.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
@Autowired
private RoleMapper roleMapper;
@Override
public List<Role> test() {
List<Role> roles = roleMapper.selectList(null);
return roles;
}
}
####controller--- RoleController
java
// RoleController 实现接口返回前端
package com.xiaolibao.javacxyxiaolibao.controller;
import com.xiaolibao.javacxyxiaolibao.model.Role;
import com.xiaolibao.javacxyxiaolibao.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/role")
public class RoleController {
@Autowired
private IRoleService roleService;
@GetMapping("/test")
public List<Role> test(){
List<Role> test = roleService.test();
return test;
}
}