当前位置: 首页 > news >正文

备案网站 备注内容怎么建设大型商务网站

备案网站 备注内容,怎么建设大型商务网站,wp做网站,销售管理系统哪种好一点在Spring MVC的帮助下开发Web应用程序意味着要创建几个逻辑架构层。 层之一是DAO#xff08;存储库#xff09;层。 它负责与数据库进行通信。 如果您至少开发了DAO层一次#xff0c;则应该知道它涉及许多样板代码。 Spring Data本身就是与DAO相关的日常工作的一部分。 在帖… 在Spring MVC的帮助下开发Web应用程序意味着要创建几个逻辑架构层。 层之一是DAO存储库层。 它负责与数据库进行通信。 如果您至少开发了DAO层一次则应该知道它涉及许多样板代码。 Spring Data本身就是与DAO相关的日常工作的一部分。 在帖子中我将提供一个应用程序示例它将结合Spring MVCMySQL和Maven演示Spring DataJPA 。 Hibernate将用作JPA的实现。 您可能知道我是基于Java的配置的忠实拥护者因此我将使用这种方法来配置Spring Data。 在本教程的最后您可以找到GitHub上示例项目的链接。 制备 在本文中我将重点介绍Spring数据因此我将忽略所有超出主题的内容。 但首先我想提供大量链接这些链接可以在本教程的上下文中为您提供帮助。 使用Maven在Eclipse中创建动态Web项目 。 具有基于Java配置的简单Spring MVC应用程序 。 Spring MVC Hibernate示例应用程序。 这些链接应针对阅读文章期间可能发生的90的问题给出答案。 让我们从在MySQL中创建表开始 CREATE TABLE shops (id int(6) NOT NULL AUTO_INCREMENT,name varchar(60) NOT NULL,employees_number int(6) NOT NULL,PRIMARY KEY (id) ) ENGINEInnoDB AUTO_INCREMENT6 DEFAULT CHARSETutf8; 现在我们可以继续执行Java代码 Entity Table(name shops) public class Shop {IdGeneratedValueprivate Integer id;private String name;Column(name employees_number)private Integer emplNumber;public Integer getId() {return id;}public void setId(Integer id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Integer getEmplNumber() {return emplNumber;}public void setEmplNumber(Integer emplNumber) {this.emplNumber emplNumber;} }Spring数据的配置 我相信该项目的屏幕截图将帮助您了解发生了什么。 在属性文件中集中所有配置数据 #DB properties: db.drivercom.mysql.jdbc.Driver db.urljdbc:mysql://localhost:3306/hibnatedb db.usernamehibuser db.passwordroot#Hibernate Configuration: hibernate.dialectorg.hibernate.dialect.MySQL5InnoDBDialect hibernate.show_sqltrue entitymanager.packages.to.scancom.spr.model WebAppConfig类包含所有基于Java的配置 Configuration EnableWebMvc EnableTransactionManagement ComponentScan(com.spr) PropertySource(classpath:application.properties) EnableJpaRepositories(com.spr.repository) public class WebAppConfig {private static final String PROPERTY_NAME_DATABASE_DRIVER db.driver;private static final String PROPERTY_NAME_DATABASE_PASSWORD db.password;private static final String PROPERTY_NAME_DATABASE_URL db.url;private static final String PROPERTY_NAME_DATABASE_USERNAME db.username;private static final String PROPERTY_NAME_HIBERNATE_DIALECT hibernate.dialect;private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL hibernate.show_sql;private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN entitymanager.packages.to.scan;Resourceprivate Environment env;Beanpublic DataSource dataSource() {DriverManagerDataSource dataSource new DriverManagerDataSource();dataSource.setDriverClassName(env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));dataSource.setUrl(env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));dataSource.setUsername(env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));dataSource.setPassword(env.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));return dataSource;}Beanpublic LocalContainerEntityManagerFactoryBean entityManagerFactory() {LocalContainerEntityManagerFactoryBean entityManagerFactoryBean new LocalContainerEntityManagerFactoryBean();entityManagerFactoryBean.setDataSource(dataSource());entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);entityManagerFactoryBean.setPackagesToScan(env. getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));entityManagerFactoryBean.setJpaProperties(hibProperties());return entityManagerFactoryBean;}private Properties hibProperties() {Properties properties new Properties();properties.put(PROPERTY_NAME_HIBERNATE_DIALECT, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));properties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));return properties;}Beanpublic JpaTransactionManager transactionManager() {JpaTransactionManager transactionManager new JpaTransactionManager();transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());return transactionManager;}Beanpublic UrlBasedViewResolver setupViewResolver() {UrlBasedViewResolver resolver new UrlBasedViewResolver();resolver.setPrefix(/WEB-INF/pages/);resolver.setSuffix(.jsp);resolver.setViewClass(JstlView.class);return resolver;}} 请注意EnableJpaRepositories批注。 它允许使用JPA存储库。 com.spr.repository软件包将被扫描以检测存储库。 在entityManagerFactory bean中我确定将Hibernate用作JPA实现。 初始化类将被省略。 DAO和服务层 Shop实体的存储库 package com.spr.repository;import org.springframework.data.jpa.repository.JpaRepository;import com.spr.model.Shop;public interface ShopRepository extends JpaRepositoryshop, integer {} 无疑它是本教程中最简单的代码段。 但这需要最高的关注。 JpaRepository接口包含可以用任何实体执行的基本操作CRUD操作。 您可以在官方文档页面上找到更多信息。 这是ShopService接口的代码 public interface ShopService {public Shop create(Shop shop);public Shop delete(int id) throws ShopNotFound;public List findAll();public Shop update(Shop shop) throws ShopNotFound;public Shop findById(int id);} 并实现服务接口 import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;import com.spr.exception.ShopNotFound; import com.spr.model.Shop; import com.spr.repository.ShopRepository;Service public class ShopServiceImpl implements ShopService {Resourceprivate ShopRepository shopRepository;OverrideTransactionalpublic Shop create(Shop shop) {Shop createdShop shop;return shopRepository.save(createdShop);}OverrideTransactionalpublic Shop findById(int id) {return shopRepository.findOne(id);}OverrideTransactional(rollbackForShopNotFound.class)public Shop delete(int id) throws ShopNotFound {Shop deletedShop shopRepository.findOne(id);if (deletedShop null)throw new ShopNotFound();shopRepository.delete(deletedShop);return deletedShop;}OverrideTransactionalpublic List findAll() {return shopRepository.findAll();}OverrideTransactional(rollbackForShopNotFound.class)public Shop update(Shop shop) throws ShopNotFound {Shop updatedShop shopRepository.findOne(shop.getId());if (updatedShop null)throw new ShopNotFound();updatedShop.setName(shop.getName());updatedShop.setEmplNumber(shop.getEmplNumber());return updatedShop;}} 这样就可以使用ShopRepository。 控制者 最后我可以在控制器中使用ShopSrviceImpl类。 所有JSP页面将被省略因此您可以在GitHub上找到它们的源代码。 Controller RequestMapping(value/shop) public class ShopController {Autowiredprivate ShopService shopService;RequestMapping(value/create, methodRequestMethod.GET)public ModelAndView newShopPage() {ModelAndView mav new ModelAndView(shop-new, shop, new Shop());return mav;}RequestMapping(value/create, methodRequestMethod.POST)public ModelAndView createNewShop(ModelAttribute Shop shop, final RedirectAttributes redirectAttributes) {ModelAndView mav new ModelAndView();String message New shop shop.getName() was successfully created.;shopService.create(shop);mav.setViewName(redirect:/index.html);redirectAttributes.addFlashAttribute(message, message); return mav; }RequestMapping(value/list, methodRequestMethod.GET)public ModelAndView shopListPage() {ModelAndView mav new ModelAndView(shop-list);List shopList shopService.findAll();mav.addObject(shopList, shopList);return mav;}RequestMapping(value/edit/{id}, methodRequestMethod.GET)public ModelAndView editShopPage(PathVariable Integer id) {ModelAndView mav new ModelAndView(shop-edit);Shop shop shopService.findById(id);mav.addObject(shop, shop);return mav;}RequestMapping(value/edit/{id}, methodRequestMethod.POST)public ModelAndView editShop(ModelAttribute Shop shop,PathVariable Integer id,final RedirectAttributes redirectAttributes) throws ShopNotFound {ModelAndView mav new ModelAndView(redirect:/index.html);String message Shop was successfully updated.;shopService.update(shop);redirectAttributes.addFlashAttribute(message, message); return mav;}RequestMapping(value/delete/{id}, methodRequestMethod.GET)public ModelAndView deleteShop(PathVariable Integer id,final RedirectAttributes redirectAttributes) throws ShopNotFound {ModelAndView mav new ModelAndView(redirect:/index.html); Shop shop shopService.delete(id);String message The shop shop.getName() was successfully deleted.;redirectAttributes.addFlashAttribute(message, message);return mav;}} 摘要 Spring Data是非常强大的武器它可以帮助您更快地开发应用程序并避免数百个样板代码字符串。 使用Spring Data是在应用程序中创建DAO层的最便捷方法因此请不要在项目中忽略它。 参考 Fruzenshtein的笔记博客中的Spring JPA Data Hibernate MySQL Maven来自我们的JCG合作伙伴 Alexey Zvolinskiy。 翻译自: https://www.javacodegeeks.com/2013/05/spring-jpa-data-hibernate-mysql-maven.html
http://www.zqtcl.cn/news/151828/

相关文章:

  • 琪觅公司网站开发中文网页开发工具
  • 教育网站制作设计成都网络营销公司
  • 怎么查看一个网站页面的seo优化情况网站建站建设首选上海黔文信息科技有限公司2
  • 威海网站建设价格深圳优美网络科技有限公司
  • 做网站用什么系统建设网站投资多少
  • 凡科建站官网 网络服务抚顺 网站建设
  • 学校网站的建设方案西安企业seo外包服务公司
  • 建设租车网站深圳ww
  • 推广网络网站潜江资讯网一手机版
  • 凡科网站自己如何做毕设 做网站
  • 一起做网站逛市场百度权重查询网站
  • 专业网站优化推广网站核查怎么抽查
  • 牡丹江站salong wordpress
  • 网站建设公司做网站要多少费用有哪些外国网站国内可以登录的
  • 天津建站平台网页制作免费的素材网站
  • 建设网站需要专业哪个企业提供电子商务网站建设外包
  • 公司网站建设及维护网站建设思维
  • 那个网站可以学做西餐17做网站广州沙河
  • 品牌网站建设哪里好京东网站建设案例
  • 亚马逊海外版网站深圳市工商注册信息查询网站
  • 新乐做网站优化网站上漂亮的甘特图是怎么做的
  • 新网站应该怎么做seo品牌推广方案思维导图
  • 想要网站导航推广页浅谈中兴电子商务网站建设
  • 免费引流在线推广成都网站优化费用
  • 老河口市网站佛山市点精网络科技有限公司
  • word模板免费网站seo引擎优化是做什么的
  • 办网站怎么赚钱鄠邑建站 网站建设
  • 宜春网站建设推广微信小程序开发
  • 巴南城乡建设网站免费网站建设软件大全
  • 湖南网站建设公公司没有自己的网站