💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 1、在public端定义接口 ``` package nc.app.rest; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import nc.bs.framework.adaptor.IHttpServletAdaptor; import nc.bs.framework.common.NCLocator; import nc.app.itf.IAppRestService; public class AppRestHttpServlet implements IHttpServletAdaptor { public void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 调用其他EJB接口 IAppRestService itf = NCLocator.getInstance().lookup( IAppRestService.class); Object data = itf.doAction(actionImpl.trim(), (Map) json.get("params")); response.setCharacterEncoding("utf-8"); response.setContentType("application/json;charset=UTF-8"); response.getWriter().print("调用成功"); } } ``` ![](https://img.kancloud.cn/4b/bb/4bbb933d846c8d5a4ae595beb306a05a_1052x442.png) # 2、新建upm文件用于发布接口 upm文件名在所属模块下不重复,只能是字母和数字且字母开头。 访问地址IP:PORT/service/appRest > IP:PORT/service/ 是固定格式,加上 component 的name属性即可 在开发工具内新建upm文件后会自动同步到配置的NCHOME/modules下当前项目对应模块内 ``` <?xml version='1.0' encoding='UTF-8'?> <module name="pu20220220"> <public> <component name="appRest" accessProtected="false" remote="false" singleton="true" tx="NONE"> <implementation>nc.app.rest.AppRestHttpServlet</implementation> </component> </public> </module> ``` ![](https://img.kancloud.cn/46/ce/46ce408756c2597aa745cd860559aef4_852x499.png) ![](https://img.kancloud.cn/4d/00/4d00c7a58a2f0cd26d1b894860e3bab3_501x492.png) # 3、注意事项 ## 3.1、 接口不生效 开发工具重启后接口不生效,则需要去NCHOME里重新部署EJB ![ ](images/screenshot_1645352682470.png) ## 3.2 、http接口内操作多个表失败事物不回滚 http接口是未启用事物的,通常http接口内我们不做任何业务逻辑,只做接口鉴权和调用EJB接口,EJB接口启用数据库事物处理具体业务。