### Run Development Environment Source: https://doc.niucloud.com/java.html?keywords=%2FadminFrontend%2FbuildUpload After installing dependencies, execute this command to start the development server. This is for local development and testing. ```bash npm run dev ``` -------------------------------- ### Install Dependencies Source: https://doc.niucloud.com/java.html?keywords=%2FadminFrontend%2FbuildUpload Run this command in the \/admin directory to install project dependencies. Ensure you have Node.js and npm installed. ```bash npm install ``` -------------------------------- ### Install Baota Panel on Fedora Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FlinuxDeployment Use this script to install the Baota Panel on Fedora systems. Follow on-screen prompts for confirmation. ```bash wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh ``` -------------------------------- ### API Definition Examples Source: https://doc.niucloud.com/java.html?keywords=%2FadminFrontend%2Finterface Demonstrates the standard format for defining API interfaces as functions returning encapsulated request objects. Includes examples for GET, POST, PUT, and DELETE operations. ```typescript /** * 登录接口 * @param params 登录参数 * @param app_type 应用类型 */ export function login(params: Record, app_type: string) { return request.get(`login/${ app_type }`, { params }) } /** * 添加用户组 * @param params 用户组参数 * @returns Promise */ export function addRole(params: Record) { return request.post(`sys/role`, params, { showSuccessMessage: true }) } /** * 编辑用户 * @param params 用户参数 */ export function editUser(params: Record) { return request.put(`user/user/${ params.uid }`, params, { showSuccessMessage: true }) } /** * 删除用户 * @param uid 用户ID */ export function deleteUser(uid: number) { return request.delete(`user/user/${ uid }`, { showSuccessMessage: true }) } ``` -------------------------------- ### Service Interface Naming Convention Examples Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FserviceLayer Provides examples of the standard naming convention for service interfaces, which starts with 'I', followed by the business theme, and ends with 'Service'. ```java ISiteService // 站点服务接口 IUserService // 用户服务接口 IOrderService // 订单服务接口 ``` -------------------------------- ### Install Baota Panel on Ubuntu/Deepin Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FlinuxDeployment Use this script to install the Baota Panel on Ubuntu or Deepin systems. Follow on-screen prompts for confirmation. ```bash wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh ``` -------------------------------- ### Install Baota Panel on Debian Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FlinuxDeployment Use this script to install the Baota Panel on Debian systems. Follow on-screen prompts for confirmation. ```bash wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && bash install.sh ``` -------------------------------- ### Run Mini-Program Development Server Source: https://doc.niucloud.com/java.html?keywords=%2Funi-app%2FgettingStarted Starts the development server for mini-programs, enabling preview in the WeChat developer tools. ```bash npm run dev:mp-weixin ``` -------------------------------- ### Start NiuCloud Service Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FwindowsDeployment Execute the `niucloud.bat` script located in the `webroot` directory to start the NiuCloud Admin Java service. Select option '1' when prompted. ```batch webroot/niucloud.bat ``` -------------------------------- ### Install Baota Panel on CentOS Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FlinuxDeployment Use this script to install the Baota Panel on CentOS systems. Follow on-screen prompts for confirmation. ```bash yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh ``` -------------------------------- ### Import and Use Article APIs Source: https://doc.niucloud.com/java.html?keywords=%2Fweb%2Finterface Demonstrates how to import and use article-related API functions within a component's setup function. ```javascript // 在组件中导入并使用API import { getArticleList, getArticleDetail } from '@/app/api/article' export default { setup() { // 获取文章列表 const fetchArticles = async () => { try { const params = { page: 1, size: 10, category_id: 1 } const result = await getArticleList(params) console.log('文章列表:', result) } catch (error) { console.error('获取文章列表失败:', error) } } // 获取文章详情 const fetchArticleDetail = async (id: number) => { try { const result = await getArticleDetail(id) console.log('文章详情:', result) } catch (error) { console.error('获取文章详情失败:', error) } } return { fetchArticles, fetchArticleDetail } } } ``` -------------------------------- ### NuxtLink Navigation Examples Source: https://doc.niucloud.com/java.html?keywords=%2Fweb%2Frouting Demonstrates how to use the NuxtLink component for navigation, including basic links and links with query parameters. ```html 登录 文章详情 ``` -------------------------------- ### Uni-App Subpackage Configuration Example Source: https://doc.niucloud.com/java.html?keywords=%2Funi-app%2Frouting Illustrates how to configure subpackages for lazy loading in Uni-App. This helps optimize application performance by loading pages on demand. ```json "subPackages": [ { "root": "app/components", "pages": [] }, { "root": "app/pages/member", "pages": [ // 会员相关页面配置 ] } ] ``` -------------------------------- ### Run uniapp H5 Development Server Source: https://doc.niucloud.com/java.html?keywords=%2FlocalDevDeployment%2FuniappSiteDeployment Start the uniapp H5 development server to preview your application. This command compiles the uniapp project and serves it locally, allowing you to access it via a web browser. ```bash npm run dev:h5 ``` -------------------------------- ### Build for Production Source: https://doc.niucloud.com/java.html?keywords=%2FadminFrontend%2FbuildUpload If dependencies are already installed and the environment has been run previously, use this command to compile and build the project for production. This generates the \/dist folder. ```bash npm run build ``` -------------------------------- ### Boot Module Entry Point - Boot.java Source: https://doc.niucloud.com/java.html?keywords=%2FdevelopGuide%2FprojectStartup The main entry point for the 'niucloud-boot' module. It handles environment validation, configuration loading, and process monitoring for the core application. Ensure Java 17 is installed and necessary configurations are present. ```java package com.niu.boot; import com.niu.boot.config.BootConfig; import com.niu.boot.process.EnvironmentValidator; import com.niu.boot.process.ProcessMonitor; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Boot { public static void main(String[] args) { BootConfig bootConfig = new BootConfig(args, "boot.yml"); EnvironmentValidator environmentValidator = EnvironmentValidator.getInstance(bootConfig); if (environmentValidator.checkEnvironment()) { if (!environmentValidator.checkJreUsable()) { System.out.println("当前Java环境是:" + bootConfig.getJavaVersion() + ",请安装Java17的运行环境."); System.exit(0); } if (!environmentValidator.readAppEnv()) { System.out.println("请在 [" + bootConfig.getAppEnvPath() + "] 文件中进行配置."); System.exit(0); } if (!environmentValidator.checkMysqlUsable()) { System.out.println("请在 [" + bootConfig.getAppEnvPath() + "] 文件中进行配置, MySQL连接."); System.exit(0); } if (!environmentValidator.checkRedisUsable()) { System.out.println("请在 [" + bootConfig.getAppEnvPath() + "] 文件中进行配置, Redis连接."); System.exit(0); } } for (String arg: args) { if (arg.equals("--install-addon")) { try (RandomAccessFile raf = new RandomAccessFile("install_addon.dat", "rw"); FileChannel channel = raf.getChannel()) { MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 100); buffer.put("install-addon".getBytes()); } catch (Exception e) { } } } bootConfig.printArguments(); new ProcessMonitor(bootConfig).start(); Runtime.getRuntime().addShutdownHook(new ProcessMonitor.Shutdown()); } } ``` -------------------------------- ### Complete Hotel Entity Class Example Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FentityManagement A comprehensive example of a hotel entity class, showcasing all standard annotations, field definitions with comments, and data types as per the project's conventions. ```java package com.niu.tourism.entity.hotel; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import java.io.Serializable; /** * 酒店实体类 */ @Data @TableName("tourism_hotel") public class TourismHotel implements Serializable { private static final long serialVersionUID = 1L; /** 酒店ID */ @TableId(value = "hotel_id", type = IdType.AUTO) private Integer hotelId; /** 酒店星级 */ private Integer hotelStar; /** 酒店标签,多个逗号分隔 */ private String hotelTag; /** 酒店介绍 */ private String hotelDesc; /** 站点ID */ private Integer siteId; /** 酒店名称 */ private String hotelName; /** 酒店封面 */ private String hotelCover; /** 酒店图片 */ private String hotelImages; /** 酒店参数 */ private String hotelAttribute; /** 省ID */ private Integer provinceId; /** 市ID */ private Integer cityId; /** 区县ID */ private Integer districtId; /** 地址 */ private String address; /** 完整地址 */ private String fullAddress; /** 经度 */ private String longitude; /** 纬度 */ private String latitude; /** 酒店状态 - 1正常 0下架 */ private Integer hotelStatus; /** 周边交通 */ private String aroundTraffic; /** 周边美食 */ private String aroundFood; /** 创建时间 */ private Long createTime; /** 是否删除 - 0正常 1删除 */ private Integer isDelete; /** 删除时间 */ private Long deleteTime; /** 海报ID */ private Integer posterId; } ``` -------------------------------- ### Plugin Site Menu Definition Example Source: https://doc.niucloud.com/java.html?keywords=%2FpluginDevelopment%2FpluginMenu An example of a JSON configuration for defining site-side menus within a plugin. It includes nested structures for directories, menus, and function buttons, specifying details like menu name, key, parent, type, icon, API URL, router path, view path, methods, sort order, status, and visibility. ```json /**************************site.json菜单配置***/ { "menu": [ { "menu_name": "测试插件", "menu_short_name": "", "menu_key": "lg_cms", "parent_key": "", "menu_type": 0, "icon": "", "api_url": "", "router_path": "", "view_path": "", "methods": "", "sort": 100, "status": 1, "is_show": 1, "children": [ { "menu_name": "测试插件", "menu_short_name": "", "menu_key": "lg_cms_hello_world", "parent_key": "", "menu_type": 1, "icon": "", "api_url": "lg_cms/hello_world", "router_path": "lg_cms/hello_world", "view_path": "hello_world/index", "methods": "get", "sort": 100, "status": 1, "is_show": 1, "children": [ { "menu_name": "添加测试数据", "menu_short_name": "", "menu_key": "lg_cms_hello_world_add", "parent_key": "lg_cms_hello_world", "menu_type": 2, "icon": "", "api_url": "lg_cms/hello_world", "router_path": "", "view_path": "", "methods": "post", "sort": 0, "status": 1, "is_show": 0 } ] } ] } ], "delete": [ ] } ``` -------------------------------- ### Example SQL Statements for Renaming Tables Source: https://doc.niucloud.com/java.html?keywords=%2FfunctionConfig%2FdatabasePrefixModification These are example `ALTER TABLE` statements generated by the previous query. Execute these SQL commands to rename your database tables to the new prefix. ```sql ALTER TABLE nc_addon RENAME TO ns_addon; ALTER TABLE nc_addon_log RENAME TO ns_addon_log; ALTER TABLE nc_applet_site_version RENAME TO ns_applet_site_version; ALTER TABLE nc_applet_version RENAME TO ns_applet_version; ALTER TABLE nc_cms_article RENAME TO ns_cms_article; ALTER TABLE nc_cms_article_category RENAME TO ns_cms_article_category; 。。。 ``` -------------------------------- ### Get Product List Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Retrieves a paginated list of shop goods with optional search parameters. ```APIDOC ## GET /adminapi/shop/goods ### Description Retrieves a paginated list of shop goods with optional search parameters. ### Method GET ### Endpoint /adminapi/shop/goods ### Parameters #### Query Parameters - **pageParam** (PageParam) - Required - Pagination parameters. - **searchParam** (ShopGoodsSearchParam) - Required - Search parameters for goods. ### Response #### Success Response (200) - **data** (PageResult) - The paginated list of shop goods. ``` -------------------------------- ### Get Product Details Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Retrieves the details of a specific shop good by its ID. ```APIDOC ## GET /adminapi/shop/goods/{id} ### Description Retrieves the details of a specific shop good by its ID. ### Method GET ### Endpoint /adminapi/shop/goods/{id} ### Parameters #### Path Parameters - **id** (Integer) - Required - The ID of the product to retrieve. ### Response #### Success Response (200) - **data** (ShopGoodsInfoVo) - The details of the shop good. ``` -------------------------------- ### Complete Scheduled Task Implementation in Java Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FscheduledTasks This example shows a full implementation of a scheduled task for closing expired sites. It includes dependency injection for services and the core execution logic. ```java package com.niu.core.job.site; import com.niu.core.common.component.context.SpringContext; import com.niu.core.common.component.job.AbstractJobProvider; import com.niu.core.common.component.job.IJobProvider; import com.niu.core.common.component.job.annotation.JobProvider; import com.niu.core.service.core.site.ICoreSiteService; import org.quartz.JobExecutionContext; @JobProvider(key = "SiteExpireCloseJob", name = "站点到期自动关闭", describe = "站点到期自动关闭", source = "core") public class SiteExpireCloseJob extends AbstractJobProvider implements IJobProvider { private ICoreSiteService coreSiteService() { return SpringContext.bean(ICoreSiteService.class); } @Override public void exec(JobExecutionContext context) { coreSiteService().siteExpireClose(); } } ``` -------------------------------- ### Direct API Call Example in Vue Component Source: https://doc.niucloud.com/java.html?keywords=%2FadminFrontend%2Finterface Shows how to directly import and use API functions like `getRoleList` and `addRole` within a Vue component's Composition API. Includes asynchronous data fetching and error handling. ```typescript import { ref } from 'vue' import { getRoleList, addRole } from '@/app/api/sys' const roleList = ref([]) // 获取角色列表 const loadRoleList = async () => { try { const res = await getRoleList({ page: 1, limit: 10, keyword: '' }) roleList.value = res.data.list } catch (error) { console.error('获取角色列表失败', error) } } // 添加角色 const handleAddRole = async (formData) => { try { await addRole({ role_name: formData.roleName, role_desc: formData.roleDesc, status: formData.status }) await loadRoleList() // 添加成功后刷新列表 } catch (error) { // 错误信息会由请求拦截器自动显示 } } ``` -------------------------------- ### Interface Definition Examples Source: https://doc.niucloud.com/java.html?keywords=%2FadminFrontend%2Finterface API interfaces are defined as independent functions that return encapsulated request objects. Examples demonstrate common operations like login, adding roles, editing users, and deleting users. ```APIDOC ## API Interface Definitions ### Description Each API is a function returning a request promise, following a consistent definition pattern. ### Examples #### Login API ```typescript /** * Login API * @param params Login parameters * @param app_type Application type */ export function login(params: Record, app_type: string) { return request.get(`login/${ app_type }`, { params }) } ``` #### Add Role API ```typescript /** * Add user role * @param params Role parameters * @returns Promise */ export function addRole(params: Record) { return request.post(`sys/role`, params, { showSuccessMessage: true }) } ``` #### Edit User API ```typescript /** * Edit user * @param params User parameters */ export function editUser(params: Record) { return request.put(`user/user/${ params.uid }`, params, { showSuccessMessage: true }) } ``` #### Delete User API ```typescript /** * Delete user * @param uid User ID */ export function deleteUser(uid: number) { return request.delete(`user/user/${ uid }`, { showSuccessMessage: true }) } ``` ``` -------------------------------- ### Entity Field Data Type Examples Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FentityManagement Provides examples of common data type mappings between database and Java for entity fields, including Integer/Long for numbers, String for text, BigDecimal for currency, Long for timestamps, and Integer for booleans. ```java private Integer hotelId; // 整数类型 private String hotelName; // 字符串类型 private BigDecimal price; // 金额类型 private Long createTime; // 时间戳 private Integer isDelete; // 布尔值(0/1) ``` -------------------------------- ### Add Product Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Adds a new shop good to the system. ```APIDOC ## POST /adminapi/shop/goods ### Description Adds a new shop good to the system. ### Method POST ### Endpoint /adminapi/shop/goods ### Parameters #### Request Body - **addParam** (ShopGoodsParam) - Required - The parameters for adding a new product. ### Response #### Success Response (200) - **data** (Object) - Indicates successful addition. ``` -------------------------------- ### Get Product Recycle Bin List Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Retrieves a paginated list of goods in the recycle bin. ```APIDOC ## GET /adminapi/shop/goods/recyclePage ### Description Retrieves a paginated list of goods in the recycle bin. ### Method GET ### Endpoint /adminapi/shop/goods/recyclePage ### Parameters #### Query Parameters - **pageParam** (PageParam) - Required - Pagination parameters. - **searchParam** (ShopGoodsSearchParam) - Required - Search parameters for goods. ### Response #### Success Response (200) - **data** (PageResult) - The paginated list of goods in the recycle bin. ``` -------------------------------- ### 验证 Node.js 和 npm 安装 Source: https://doc.niucloud.com/java.html?keywords=%2FlocalDevDeployment%2FdevelopmentEnvironment 在安装 Node.js 后,使用此命令验证其版本和 npm 的版本。确保 Node.js 版本符合项目要求。 ```bash node -v # 显示Node.js版本 npm -v # 显示npm版本 ``` -------------------------------- ### Core Application Entry Point - WebAppApplication.java Source: https://doc.niucloud.com/java.html?keywords=%2FdevelopGuide%2FprojectStartup The main entry point for the 'niucloud-web-app' module. It serves as the Spring Boot application's main class, enabling asynchronous operations, scheduled tasks, and scanning for MyBatis mappers and components. ```java package com.niu.app; import com.niu.app.common.context.SpringBeanNameGenerator; import com.niu.app.common.loader.PluginBufferingApplicationStartup; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.env.Environment; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @EnableAsync @EnableScheduling @MapperScan(basePackages = {"com.*.**.mapper.*", "com.niu.*.mapper"}) ``` -------------------------------- ### Check Java Version Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FwindowsDeployment Verify that your Java Development Kit (JDK) is installed and accessible by running this command in your terminal. ```bash java -version ``` -------------------------------- ### Controller Basic Structure Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Demonstrates the basic structure of a controller class using Spring Boot, including RestController, RequestMapping, and Description annotations. ```APIDOC ## Controller Basic Structure ### Basic Controller Implementation ```java @RestController @RequestMapping("adminapi/shop/goods") @Description("商品管理") public class ShopGoodsController { @Resource IShopGoodsService goodsService; // Controller methods... } ``` ``` -------------------------------- ### Build Mini-Program Code Package Source: https://doc.niucloud.com/java.html?keywords=%2Funi-app%2FgettingStarted Generates the code package for mini-program platforms. ```bash npm run build:mp-weixin ``` -------------------------------- ### 验证 Java 环境安装 Source: https://doc.niucloud.com/java.html?keywords=%2FlocalDevDeployment%2FdevelopmentEnvironment 安装 JDK 17 后,使用这些命令验证 Java 运行环境和编译器的版本。确保 Java 环境已正确配置。 ```bash java -version # 查看Java运行环境版本 javac -version # 查看Java编译器版本 ``` -------------------------------- ### Path Variable Parameter Handling Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Demonstrates how to extract path variables for GET requests. The `@PathVariable` annotation binds URL segments to method parameters. ```java @GetMapping("/{id}") @Description("获取商品详情") public Result info(@PathVariable("id") Integer id) { ShopGoodsInfoVo info = goodsService.info(id); return Result.success(info); } ``` -------------------------------- ### MyBatis-Plus-Join Nested OR Query Example Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FdatabaseQuery Demonstrates constructing complex nested OR conditions for database queries. This is useful for scenarios requiring flexible matching across multiple criteria. ```java queryWrapper.or(i -> i.and(j -> j.eq("name", "李白").eq("status", "alive")) .or(j -> j.eq("name", "杜甫").eq("status", "alive"))); ``` -------------------------------- ### Build H5 Application Source: https://doc.niucloud.com/java.html?keywords=%2Funi-app%2FgettingStarted Generates the production-ready build for H5 applications. ```bash npm run build:h5 ``` -------------------------------- ### Define Addon Mapper Interface Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FmapperView Example of defining a Mapper interface for the Addon entity, extending MPJBaseMapper for MyBatis-Plus join capabilities. Ensure the @Mapper annotation is present. ```java package com.niu.core.mapper.addon; import com.github.yulichang.base.MPJBaseMapper; import com.niu.core.entity.addon.Addon; import org.apache.ibatis.annotations.Mapper; /** * 插件 Mapper */ @Mapper public interface AddonMapper extends MPJBaseMapper { } ``` -------------------------------- ### Permission Control Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2Fcontroller Illustrates how to implement permission control at both the class level (requiring login for all methods) and method level (requiring specific permissions). ```APIDOC ## Permission Control ### Class-Level Permission Control ```java @RestController @RequestMapping("adminapi/shop/goods") @SaCheckLogin // Entire controller requires login public class ShopGoodsController { // ... } ``` ### Method-Level Permission Control ```java @PutMapping("/{id}/status") @Description("修改商品状态") @SaCheckPermission("shop:goods:status") // Requires specific permission public Result editStatus(@PathVariable("id") Integer id, @RequestBody StatusParam statusParam) { goodsService.editStatus(id, statusParam); return Result.success(); } ``` ``` -------------------------------- ### Create MySQL Database Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FwindowsDeployment Use this SQL command to create the database required for NiuCloud Admin Java. Ensure the character set and collation are set correctly. ```sql CREATE DATABASE niucloud_admin_java CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ``` -------------------------------- ### Configure MySQL Connection Source: https://doc.niucloud.com/java.html?keywords=%2FserverDeployment%2FwindowsDeployment Update the `application-prod.yml` file with your MySQL connection details. This includes the database URL, username, and password. ```yaml url: jdbc:mysql://127.0.0.1:3306/niucloud_admin_java?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: root ``` -------------------------------- ### Entity Field Naming Convention Example Source: https://doc.niucloud.com/java.html?keywords=%2FjavaServer%2FentityManagement Illustrates the camelCase naming convention for entity fields, ensuring they correspond to database columns and avoid Java keywords. Meaningful names and avoidance of abbreviations are recommended. ```java private String hotelName; // 酒店名称 private Integer hotelStar; // 酒店星级 private String fullAddress; // 完整地址 private Integer isDelete; // 是否删除 ```