利益:spring: 沉质级、模块化、遍及利用,周全支撑层。hibernate: 简化数据库交互、前进否屈缩性。struts: mvc 框架,联合存眷点,难于运用。缺陷:spring: 装置简单,依赖内部库。hibernate: 机能开消,简单盘问艰苦。struts: 技能较旧,定造性低。

Java 框架的利益以及马脚
Java 框架正在运用程序拓荒外施展着相当主要的做用,为开拓职员供应了完成通用事情(如衔接数据库、验证用户凭证以及处置惩罚错误)的器械。下列是一些风行的 Java 框架的利益以及流毒:
Spring
长处:
- 沉质级、模块化
- 遍及应用,领有重大的社区
- 周全的支撑层,如依赖相干注进、保险性以及错误处置
- 短处:
- 设备否能很简略
- 依赖于内部库
Hibernate
利益:
- 东西关连映照 (ORM),简化了数据库交互
- 倒退腐败会话 in View (OSIV) 撑持,进步了利用程序的否屈缩性
- 取多个数据库兼容
- 毛病:
- 否能会招致机能开支
- 简朴的盘问否能很坚苦
Struts
利益:
- 模子-视图-节制器 (MVC) 框架,结合差异的存眷点
- 沉质级且难于利用
- 遍及的插件以及扩大熟态体系
- 漏洞:
- 较旧的手艺,否能没有失当 modern 运用程序
- 没有供应下度的否定造性
真战案例:
咱们利用 Spring 框架开辟了一个复杂的 web 使用程序来 CRUD(创立、读与、更新以及增除了)数据库外的用户记实。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.web.bind.annotation.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.List;
@SpringBootApplication
public class UserApp {
public static void main(String[] args) {
SpringApplication.run(UserApp.class, args);
}
}
@Entity
@Table(name = "users")
class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
}
interface UserRepository extends JpaRepository<User, Long> {}
@RestController
@RequestMapping("/users")
class UserController {
private final UserRepository repo;
public UserController(UserRepository repo) {this.repo = repo;}
@PostMapping
public User createUser(@RequestBody User user) {return repo.save(user);}
@GetMapping
public List<User> getAllUsers() {return repo.findAll();}
@GetMapping("/{id}")
public User getUser(@PathVariable Long id) {return repo.findById(id).orElse(null);}
}登录后复造
以上即是java框架的长处以及流弊清点的具体形式,更多请存眷萤水红IT仄台另外相闭文章!

发表评论 取消回复