有没有理由不将控制器映射为接口?
在所有示例和问题中,我看到周围的控制器,都是具体的类.是否有一个原因?我想将请求映射与实现分开.当我试图@PathVariable在我的具体课程中获得一个参数时,我碰到了一堵墙.
我的Controller界面如下所示:
@Controller
@RequestMapping("/services/goal/")
public interface GoalService {
@RequestMapping("options/")
@ResponseBody
Map<String, Long> getGoals();
@RequestMapping(value = "{id}/", method = RequestMethod.DELETE)
@ResponseBody
void removeGoal(@PathVariable String id);
}
Run Code Online (Sandbox Code Playgroud)
而实施班:
@Component
public class GoalServiceImpl implements GoalService {
/* init code */
public Map<String, Long> getGoals() {
/* method code */
return map;
}
public void removeGoal(String id) {
Goal goal = goalDao.findByPrimaryKey(Long.parseLong(id));
goalDao.remove(goal);
}
}
Run Code Online (Sandbox Code Playgroud)
该getGoals()方法效果很好; 在removeGoal(String id)抛出一个异常
ExceptionHandlerExceptionResolver - Resolving exception from handler [public void
todo.webapp.controllers.services.GoalServiceImpl.removeGoal(java.lang.String)]: …Run Code Online (Sandbox Code Playgroud) 关于RESTful Web服务的大量示例没有考虑到当今许多应用程序是多用户的问题.
想象一下,暴露RESTful API的多用户后端.后端数据体系结构使用共享数据库和共享模式.每个表都包含对以下内容的引用tenant_id:
+-------------+----+-----------------+
| tenant_name| id | shared_secret |
+-------------+----+-----------------+
| bob | 1 | 2737sm45sx543 |
+-------------+----+-----------------+
| alice | 2 | 2190sl39sa8da |
+-------------+----+-----------------+
+-------------+----+-------+-----------+
| pet_name | id | type | tenant_id |
+-------------+----+-------+-----------+
| fuffy | 1 | dog | 1 |
+-------------+----+-------+-----------+
| kerry | 2 | cat | 2 |
+-------------+----+-------+-----------+
Run Code Online (Sandbox Code Playgroud)
问题1:如果有三个或更多客户端应用程序(即Android,iOS和Web App)与RESTful后端交互,您将如何对后端执行身份验证?
RESTful backend, API, HTTP-Verbs, shared database and schema
|
| …Run Code Online (Sandbox Code Playgroud) 是否有任何可能的方法让IntelliJ-not-格式成为页面的一部分?
我正在使用XHTML和facelets,但这可以应用于任何页面.如果可以在代码中执行此操作,我也很好奇.
谢谢.