赞
踩
首先先检查自己的软件版本 :
- server:
- port: 8080
-
- spring:
- datasource:
- driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://localhost:3306/zd_study?serverTimezone=GMT%2b8
- username: root
- password: 123456
只是配置好了数据能正常启动,但是不能进入端口,因为还没有配置启动类,配置如下:
代码如下:
- @RestController
- @SpringBootApplication
- public class SpringbootApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(SpringbootApplication.class, args);
- }
-
- @GetMapping("/")
- public String index(){
- return "OK";
- }
-
- }
试了下 @GetMapping 不加 ("/") 这个也已运行,目前不知道什么原因,代码:
- @RestController
- @SpringBootApplication
- public class SpringbootApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(SpringbootApplication.class, args);
- }
-
- @GetMapping
- public String index(){
- return "OK";
- }
-
- }
首先在终端cmd进入一个文件夹里,就是在这个文件夹创建前端项目
vue create vue
这样推送也不可以,显示vue: push to origin/master was rejected ,被拒绝了
导入Git项目报错:is registered as a Git root, but no Git repositories were found there_Cignus的博客-CSDN博客
npm i element-ui -S
main.js
- import Vue from 'vue'
- import ElementUI from 'element-ui';
- import 'element-ui/lib/theme-chalk/index.css';
- import App from './App.vue'
- import router from './router'
-
- Vue.use(ElementUI, {size: "small"});
-
- Vue.config.productionTip = false
-
- new Vue({
- router,
- render: h => h(App)
- }).$mount('#app')
改造Home.vue 和 APP.vue
- <template>
- <el-container style="min-height: 100vh">
- <el-aside :width="sideWidth + 'px'"
- style="background-color: rgb(238, 241, 246); box-shadow: 2px 0 6px rgb(0 21 41 / 35%);">
- <el-menu :default-openeds="['1', '3']" style="min-height: 100%; overflow-x: hidden"
- background-color="rgb(48, 65, 86)"
- text-color="#fff"
- active-text-color="#ffd04b"
- :collapse-transition="false"
- :collapse="isCollapse"
- >
- <div style="height: 60px; line-height: 60px; text-align: center">
- <img src="../assets/logo.png" alt=""
- style="width: 20px; position: relative; top: 5px; margin-right: 5px">
- <b style="color: white" v-show="logoTextShow">ERP管理系统</b>
- </div>
- <el-submenu index="1">
- <template slot="title">
- <i class="el-icon-house"></i>
- <span slot="title">主页</span>
- </template>
- </el-submenu>
- <el-submenu>
- <template slot="title"><i class="el-icon-menu"></i><span slot="title">系统管理</span></template>
- <el-menu-item index="2-1">用户管理</el-menu-item>
- <el-menu-item index="2-2">角色管理</el-menu-item>
- <el-menu-item index="2-3">菜单管理</el-menu-item>
- <el-menu-item index="2-3">文件管理</el-menu-item>
- </el-submenu>
- <el-submenu index="3">
- <template slot="title"><i class="el-icon-setting"></i><span slot="title">生产管理</span></template>
- <el-menu-item index="3-1">选项1</el-menu-item>
- <el-menu-item index="3-2">选项2</el-menu-item>
- <el-menu-item index="3-3">选项3</el-menu-item>
- <el-menu-item index="3-3">选项3</el-menu-item>
- </el-submenu>
- </el-menu>
- </el-aside>
-
- <el-container>
- <el-header style="font-size: 12px; border-bottom: 1px solid #ccc; line-height: 60px; display: flex">
- <div style="flex: 1; font-size: 20px">
- <span :class="collapseBtnClass" style="cursor: pointer" @click="collapse"></span>
- </div>
- <el-dropdown style="width: 70px; cursor: pointer">
- <i class="el-icon-setting" style="margin-right: 15px"></i>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item>修改密码</el-dropdown-item>
- <el-dropdown-item>个人信息</el-dropdown-item>
- <el-dropdown-item>退出</el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- <span>王小虎</span>
- </el-header>
-
- <el-main>
-
- <div style="margin-bottom: 30px">
- <el-breadcrumb separator="/">
- <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
- <el-breadcrumb-item>用户管理</el-breadcrumb-item>
- </el-breadcrumb>
- </div>
-
- <div style="margin: 10px 0">
- <el-input style="width: 200px" placeholder="请输入名称" suffix-icon="el-icon-search"></el-input>
- <el-input style="width: 200px" placeholder="请输入邮箱" suffix-icon="el-icon-message"
- class="ml-5"></el-input>
- <el-input style="width: 200px" placeholder="请输入地址" suffix-icon="el-icon-position"
- class="ml-5"></el-input>
- <el-button class="ml-5" type="primary">搜索</el-button>
- </div>
-
- <div style="margin: 10px 0">
- <el-button type="primary">新增 <i class="el-icon-circle-plus-outline"></i></el-button>
- <el-button type="danger">批量删除 <i class="el-icon-remove-outline"></i></el-button>
- <el-button type="primary">导入 <i class="el-icon-bottom"></i></el-button>
- <el-button type="primary">导出 <i class="el-icon-top"></i></el-button>
- </div>
-
- <el-table :data="tableData">
- <el-table-column prop="date" label="日期" width="140">
- </el-table-column>
- <el-table-column prop="name" label="姓名" width="120">
- </el-table-column>
- <el-table-column prop="address" label="地址">
- </el-table-column>
- <el-table-column label="操作" width="200" align="center">
- <template slot-scope="scope">
- <el-button type="success">编辑 <i class="el-icon-edit"></i></el-button>
- <el-button type="danger">删除 <i class="el-icon-remove-outline"></i></el-button>
- </template>
- </el-table-column>
- </el-table>
-
- <div style="padding: 10px 0">
- <el-pagination
-
- :page-sizes="[5, 10, 15, 20]"
- :page-size="10"
- layout="total, sizes, prev, pager, next, jumper"
- :total="400">
- </el-pagination>
- </div>
- </el-main>
-
- </el-container>
- </el-container>
- </template>
-
- <script>
- // @ is an alias to /src
- import HelloWorld from '@/components/HelloWorld.vue'
-
- export default {
- name: 'Home',
- data() {
- const item = {
- date: '2016-05-02',
- name: '王小虎',
- address: '上海市普陀区金沙江路 1518 弄'
- };
- return {
- tableData: Array(10).fill(item),
- collapseBtnClass: 'el-icon-s-fold',
- isCollapse: false,
- sideWidth: 200,
- logoTextShow: true,
- headerBg: 'headerBg'
- }
- },
- methods: {
- collapse() { // 点击收缩按钮触发
- this.isCollapse = !this.isCollapse
- if (this.isCollapse) { // 收缩
- this.sideWidth = 64
- this.collapseBtnClass = 'el-icon-s-unfold'
- this.logoTextShow = false
- } else { // 展开
- this.sideWidth = 200
- this.collapseBtnClass = 'el-icon-s-fold'
- this.logoTextShow = true
- }
- }
- }
- }
- </script>
-
- <style>
- .headerBg {
- background: #eee!important;
- }
- </style>
实现了如下图所示的页面:
- CREATE TABLE `sys_user` (
- `id` int NOT NULL AUTO_INCREMENT COMMENT 'id',
- `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户名',
- `password` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '密码',
- `nickname` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '昵称',
- `role` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '角色',
- `email` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '邮件',
- `phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '手机',
- `address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址',
- `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
- `avatar_val` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '头像',
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2.在springboot项目里新建 entiy,controller,mapper 文件夹,分别创建了 User实体类、UserController类和UserMapper接口。
-
- User:
-
- @Data
- public class User {
- private Integer id; //id
- private String username; //名字
- private String password;//密码
- private String nickname;//昵称
- private String role; //角色
- private String email; //邮件
- private String phone; //手机号
- private String address; //地址
- private Date createTime; //创建时间
- private String avatarVal; //头像
- }
-
- UserController:
-
- @RestController
- //https://www.cnblogs.com/fishpro/p/spring-boot-study-restcontroller.html
- //解释注解的文章
- public class UserController {
- @Resource
- private UserMapper userMapper;
- //查询所有的数据
- @GetMapping("/")
- public List<User> findAll() {
- List<User> users = userMapper.findAll();
- return users;
- }
- }
-
- UserMapper:
-
- @Mapper
- public interface UserMapper {
- @Select("select * from sys_user")
- List<User> findAll();
- }
-
Entity就是实体层,Mapper层与DAO等价,是用于直接操作数据库的层。
Service层就是对DAO层进行封装,相当于做好的工具,让用户直接用就好了。
xml文件需要进行的配置如下: namespace="com.zd.springboot.mapper.UserMapper" 表示指定的mapper文件
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zd.springboot.mapper.UserMapper">
-
- </mapper>
配置yml文件,不配置会出现错误,因为SpringBoor并不知道去哪找xml文件,需要配置路径,如下代码
- mybatis:
- mapper-locations: classpath:mapper/*.xml #扫描所有mybatis的xml文件
以下是几个文件的代码:
- //UserController:
-
- @RestController
- @RequestMapping("/user")
- public class UserController {
-
- @Resource
- private UserMapper userMapper;
-
- @Resource
- private IUserService userService;
-
- /**
- * 查询所有的数据
- * @return
- */
- @GetMapping
- public List<User> findAll() {
- List<User> users = userMapper.findAll();
- return users;
- }
-
- /**
- * 更新或者增加
- * @param user
- * @return
- */
- @PostMapping
- public Integer save(@RequestBody User user){
- int save = userService.save(user);
- return save;
- }
-
- @DeleteMapping("/{id}")
- public Integer delete(@PathVariable Integer id){
- // @PathVariable 必须要有这个注解,使得"/{id}"与Integer id保持一致
- int save = userService.deleteById(id);
- return save;
- }
-
- }
-
- //IUserService ::::
-
- public interface IUserService {
-
- int save(User user);
-
- int deleteById(Integer id);
- }
-
- //IUserServiceImpl :
-
- @Service
- public class IUserServiceImpl implements IUserService {
-
- @Resource
- private UserMapper userMapper;
-
-
- @Override
- public int save(User user) {
- if (user.getId() == null) {
- return userMapper.insert(user);
- }else {
- return userMapper.update(user);
- }
- }
-
- @Override
- public int deleteById(Integer id) {
-
- return userMapper.deleteById(id);
- }
- }
-
- //UserMapper
-
- @Mapper
- public interface UserMapper {
-
- @Select("select * from sys_user")
- List<User> findAll();
-
- int insert(User user);
-
- int update(User user);
-
- int deleteById(Integer id);
- }
-
-
- //UserMapper .xml
-
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zd.springboot.mapper.UserMapper">
-
- <update id="update">
- update sys_user
- <set>
- <if test="username != null">
- username = #{username},
- </if>
- <!-- <if test="password != null">-->
- <!-- password = #{password}-->
- <!-- </if>-->
- <if test="nickname != null">
- nickname = #{nickname},
- </if>
- <if test="email != null">
- email = #{email},
- </if>
- <if test="phone != null">
- phone = #{phone},
- </if>
- <if test="address != null">
- address = #{address}
- </if>
- </set>
- <where>
- id = #{id}
- </where>
- </update>
-
- <insert id="insert" parameterType="com.zd.springboot.entity.User">
- INSERT INTO sys_user(
- username, password,nickname,email,phone,address
- )VALUES (#{username}, #{password},#{nickname}, #{email},#{phone}, #{address})
- </insert>
-
- <delete id="deleteById">
- delete from sys_user where id = #{id}
- </delete>
-
- </mapper>
- SELECT * from sys_user limit 0,2; --第一页
- -- (2 -1) * 2 = 2
- SELECT * from sys_user limit 2,2; --第二页
- -- (3-1)* 2 = 4
- SELECT * from sys_user limit 4,2; --第三页
- -- 结论: limit第一个参数 = (pageNum - 1) * pageSize
application.yml文件里添加配置
- 添加依赖:
- <!-- mybatis-plus -->
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.5.1</version>
- </dependency>
-
- 配置MybatisPlusConfig.java :
-
- @Configuration
- @MapperScan("com.zd.springboot.mapper")
- public class MybatisPlusConfig {
-
- // 最新版
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor() {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
- return interceptor;
- }
-
- }
-
-
- 配置 application.yml:
-
- mybatis-plus:
- configuration:
- log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
添加SwaggerUI 的依赖,并进行配置SwaggerConfig.java
- 添加依赖:
-
- <!--swag-->
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>2.9.2</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>2.9.2</version>
- </dependency>
-
- 配置SwaggerConfig.java :
-
- @EnableSwagger2
- @Configuration
- public class SwaggerConfig {
- /**
- * 创建API应用
- * apiInfo() 增加API相关信息
- * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
- * 本例采用指定扫描的包路径来定义指定要建立API的目录。
- *
- * @return
- */
- @Bean
- public Docket restApi() {
- return new Docket(DocumentationType.SWAGGER_2)
- .groupName("标准接口")
- .apiInfo(apiInfo("Spring Boot中使用Swagger2构建RESTful APIs", "1.0"))
- .useDefaultResponseMessages(true)
- .forCodeGeneration(false)
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.zd.springboot.controller"))
- .paths(PathSelectors.any())
- .build();
- }
-
- /**
- * 创建该API的基本信息(这些基本信息会展现在文档页面中)
- * 访问地址:http://ip:port/swagger-ui.html
- *
- * @return
- */
- private ApiInfo apiInfo(String title, String version) {
- return new ApiInfoBuilder()
- .title(title)
- .description("更多请关注: https://blog.csdn.net/xqnode")
- .termsOfServiceUrl("https://blog.csdn.net/xqnode")
- .contact(new Contact("xqnode", "https://blog.csdn.net/xqnode", "xiaqingweb@163.com"))
- .version(version)
- .build();
- }
- }
修改以前没使用Mybatis-Plus的增删改查语句和分页查询,使用Mybatis-Plus,需把相同方法相同名字的原方法注释一下,mapper,service,.xml都需要注释一下,运行成功在Postman能够查看到数据并显示,但是在前端并没显示数据,(可能是还未进行修改前端代码)
mapper接口需继承 extends BaseMapper<User>,@Mapper 已经在MybatisPlusConfig.java进行配置,注解:@MapperScan("com.zd.springboot.mapper"),所以这里无需@Mapper
- //@Mapper
- public interface UserMapper extends BaseMapper<User> {
- }
IUserService接口需继承 extends IService<User>
- public interface IUserService extends IService<User> {
- }
IUserServiceImpl 实现类IUserServiceImpl extends ServiceImpl<UserMapper,User>
- @Service
- public class IUserServiceImpl extends ServiceImpl<UserMapper,User> implements IUserService {
- }
控制层UserController进行修改了一些修改以前没使用Mybatis-Plus的增删改查语句和分页查询,使用Mybatis-Plus进行查询,实现了用Mybatis-Plus的增删改查和分页查询,但是用PostMan进行分页查询是可以查看到数据的,在前端显示有数据,但是看不到
- @RestController
- @RequestMapping("/user")
- public class UserController {
-
-
- @Resource
- private IUserService userService;
-
- /**
- * 查询所有的数据
- *
- * @return
- */
- @GetMapping
- public List<User> findAll() {
- return userService.list();
- }
-
- /**
- * 更新或者增加
- *
- * @param user
- * @return
- */
- @PostMapping
- public Boolean save(@RequestBody User user) {
-
- return userService.saveOrUpdate(user);
- }
-
- /**
- * 通过id删除
- *
- * @param id
- * @return
- */
- @DeleteMapping("/{id}")
- public boolean delete(@PathVariable Integer id) {
- // @PathVariable 必须要有这个注解,使得"/{id}"与Integer id保持一致
- return userService.removeById(id);
- }
-
-
- /**
- * Mybatis-Plus的分页查询
- * 接口路径:/user/page?pageNum=1&pageSize=10
- * @RequestParam接受
- * @param pageNum
- * @param pageSize
- * @param username
- * @return
- */
- @GetMapping("/page")
- public IPage<User> findPage(@RequestParam Integer pageNum,
- @RequestParam Integer pageSize,
- @RequestParam(defaultValue = "") String username,
- @RequestParam(defaultValue = "") String nickname,
- @RequestParam(defaultValue = "") String address) {
- IPage<User> page = new Page<>(pageNum, pageSize);
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- if (!"".equals(username)) {
- queryWrapper.like("username", username);
- }
- if (!"".equals(nickname)) {
- queryWrapper.like("nickname", nickname);
- }
- if (!"".equals(address)) {
- queryWrapper.like("address", address);
- }
- return userService.page(page,queryWrapper);
- }
-
- }
- import axios from 'axios'
-
- const request = axios.create({
- baseURL: 'http://localhost:9090', //以后就不用在方法里写这个请求头了,直接/user这样就可以
- timeout: 5000
- })
-
- // request 拦截器
- // 可以自请求发送前对请求做一些处理
- // 比如统一加token,对请求参数统一加密
- request.interceptors.request.use(config => {
- config.headers['Content-Type'] = 'application/json;charset=utf-8';
-
- // config.headers['token'] = user.token; // 设置请求头
- return config
- }, error => {
- return Promise.reject(error)
- });
-
- // response 拦截器
- // 可以在接口响应后统一处理结果
- request.interceptors.response.use(
- response => {
- let res = response.data;
- // 如果是返回的文件
- if (response.config.responseType === 'blob') {
- return res
- }
- // 兼容服务端返回的字符串数据
- if (typeof res === 'string') {
- res = res ? JSON.parse(res) : res
- }
- return res;
- },
- error => {
- console.log('err' + error) // for debug
- return Promise.reject(error)
- }
- )
-
-
- export default request
- UserController:
-
- //批量删除
- @PostMapping("/del/batch")
- public boolean deleteBath(@RequestBody List<Integer> ids) {
- return userService.removeByIds(ids);
- }
-
-
- Home.vue
-
- save() {
- request.post("/user", this.form).then(res => {
- if (res) {
- this.$message.success("保存成功")
- this.dialogFormVisible = false
- this.load()
- } else {
- this.$message.error("保存失败")
- }
- })
- },
- handleAdd() {
- this.dialogFormVisible = true
- this.form = {}
- },
- handleEdit(row) {
- this.form = row //把列表的数据赋予row,row是表单scop
- this.dialogFormVisible = true
- },
- del(id) {
- request.delete("/user/" + id).then(res => {
- if (res) {
- this.$message.success("删除成功")
- this.load()
- } else {
- this.$message.error("删除失败")
- }
- })
- },
- delBatch() {
- let ids = this.multipleSelection.map(v => v.id) // [{}, {}, {}] => [1,2,3]
- request.post("/user/del/batch", ids).then(res => {
- if (res) {
- this.$message.success("批量删除成功")
- this.load()
- } else {
- this.$message.error("批量删除失败")
- }
- })
- },
- reset() {
- this.username = ""
- this.email = ""
- this.address = ""
- this.load()
- },
- handleSelectionChange(val) { //批量删除时选择那些存到val里
- console.log(val)
- this.multipleSelection = val
- },
- <!-- 代码生成器 -->
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-generator</artifactId>
- <version>3.5.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity</artifactId>
- <version>1.7</version>
- </dependency>
- /**
- * mp代码生成器
- * by 青哥哥
- * @since 2022-01-26
- */
- public class CodeGenerator {
-
- public static void main(String[] args) {
- generate();
- }
-
- private static void generate() {
- FastAutoGenerator.create("jdbc:mysql://localhost:3306/zd_study?serverTimezone=GMT%2b8", "root", "123456")
- .globalConfig(builder -> {
- builder.author("郑迪") // 设置作者
- .enableSwagger() // 开启 swagger 模式
- .fileOverride() // 覆盖已生成文件
- .outputDir("D:\\IDEAcode\\郑迪学习框架\\springboot\\src\\main\\java\\"); // 指定输出目录
- })
- .packageConfig(builder -> {
- builder.parent("com.zd.springboot") // 设置父包名
- .moduleName(null) // 设置父包模块名
- .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\IDEAcode\\郑迪学习框架\\springboot\\src\\main\\resources\\mapper\\")); // 设置mapperXml生成路径
- })
- .strategyConfig(builder -> {
- builder.entityBuilder().enableLombok();
- // builder.mapperBuilder().enableMapperAnnotation().build();
- builder.controllerBuilder().enableHyphenStyle() // 开启驼峰转连字符
- .enableRestStyle(); // 开启生成@RestController 控制器
- builder.addInclude("sys_user") // 设置需要生成的表名
- .addTablePrefix("t_", "sys_"); // 设置过滤表前缀
- })
- // .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
- .execute();
-
- }
- }
3、编写生成配置 - package ${package.Controller};
-
-
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.List;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-
- import ${package.Service}.${table.serviceName};
- import ${package.Entity}.${entity};
-
- #if(${restControllerStyle})
- import org.springframework.web.bind.annotation.RestController;
- #else
- import org.springframework.stereotype.Controller;
- #end
- #if(${superControllerClassPackage})
- import ${superControllerClassPackage};
- #end
-
- /**
- * <p>
- * $!{table.comment} 前端控制器
- * </p>
- *
- * @author ${author}
- * @since ${date}
- */
- #if(${restControllerStyle})
- @RestController
- #else
- @Controller
- #end
- @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
- #if(${kotlin})
- class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
-
- #else
- #if(${superControllerClass})
- public class ${table.controllerName} extends ${superControllerClass} {
- #else
- public class ${table.controllerName} {
- #end
-
- @Resource
- private ${table.serviceName} ${table.entityPath}Service;
-
- // 新增或者更新
- @PostMapping
- public Result save(@RequestBody ${entity} ${table.entityPath}) {
- ${table.entityPath}Service.saveOrUpdate(${table.entityPath});
- return Result.success();
- }
-
- @DeleteMapping("/{id}")
- public Result delete(@PathVariable Integer id) {
- ${table.entityPath}Service.removeById(id);
- return Result.success();
- }
-
- @PostMapping("/del/batch")
- public Result deleteBatch(@RequestBody List<Integer> ids) {
- ${table.entityPath}Service.removeByIds(ids);
- return Result.success();
- }
-
- @GetMapping
- public Result findAll() {
- return Result.success(${table.entityPath}Service.list());
- }
-
- @GetMapping("/{id}")
- public Result findOne(@PathVariable Integer id) {
- return Result.success(${table.entityPath}Service.getById(id));
- }
-
- @GetMapping("/page")
- public Result findPage(@RequestParam Integer pageNum,
- @RequestParam Integer pageSize) {
- QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
- queryWrapper.orderByDesc("id");
- return Result.success(${table.entityPath}Service.page(new Page<>(pageNum, pageSize), queryWrapper));
- }
-
- }
-
- #end
怎么整目前都整不对,具体显示如下图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。