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

杭州的网站建设公司哪家好求购买链接

杭州的网站建设公司哪家好,求购买链接,wordpress弹窗客服,wordpress树结构上次使用的是JdbcTemplate实现的,是比较老的方式,重新用spring boot data jdbc和jdbc client 实现一遍。也比较一下这几种的编码差异。数据库方面JAVA给了太多选择,反而不好选了。 上次就试图直接用: public interface UserRepo…

上次使用的是JdbcTemplate实现的,是比较老的方式,重新用spring boot data jdbc和jdbc client 实现一遍。也比较一下这几种的编码差异。数据库方面JAVA给了太多选择,反而不好选了。

上次就试图直接用:

public interface UserRepository extends CrudRepository<User, Long> {@Query("SELECT u.username, p.address, p.phoneNumber " +"FROM users u JOIN profiles p ON u.profileId = p.id " +"ORDER BY p.id")Page<UserProfileDTO> findUsersWithProfiles(Pageable pageable);

直接就报错了,才改为了jdbcTemplate.

这次改了:

@Repository
public interface AuthorBookRepository extends CrudRepository<Author, Integer> {@Query("SELECT a.id AS author_id, a.name AS author_name, b.id AS book_id, b.title AS book_title " +"FROM Author a JOIN Book b ON a.id = b.author_id " +"ORDER BY a.id " +"LIMIT :limit OFFSET :offset")List<AuthorBook> findAllAuthorsWithBooks(int limit, int offset);
}

注意有个坑:SQL语法错误引起的,特别是在ORDER BYLIMIT子句中使用了占位符?。在SQL中,ORDER BY子句不能使用占位符来指定列名和排序方向。我们需要在代码中动态构建SQL语句来解决这个问题。--这里就直接写,不用占位符了。

service:

@Service
public class AuthorBookService {@Autowiredprivate AuthorBookRepository authorBookRepository;public List<AuthorBook> getAuthorsWithBooks(int page, int size) {int offset = page * size;return authorBookRepository.findAllAuthorsWithBooks(size, offset);}
}

controller

@GetMapping("/authors-books")public ModelAndView getAuWithBooks(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "3") int size) {List<AuthorBook> authorsWithBooks = authorBookService.getAuthorsWithBooks(page, size);ModelAndView modelAndView = new ModelAndView("authors-books");modelAndView.addObject("authorBooks", authorsWithBooks);modelAndView.addObject("page", page);modelAndView.addObject("size", size);return modelAndView;}

验证通过,这个方法很好。

JDBC Client应该也行,没有试过。

package dev.zzz.repository;import dev.zzz.model.dto.AuthorBook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.simple.JdbcClient;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class AuthorBookService {@Autowiredprivate AuthorBookRepository authorBookRepository;private final JdbcClient jdbcClient;public AuthorBookService(JdbcClient jdbcClient) {this.jdbcClient = jdbcClient;}public List<AuthorBook> getAuthorsWithBooks(int page, int size) {int offset = page * size;return authorBookRepository.findAllAuthorsWithBooks(size, offset);}public Page<AuthorBook> getAuthors(Pageable pageable) {int limit = pageable.getPageSize();long offset = pageable.getOffset();String baseSql="SELECT a.id AS author_id, a.name AS author_name, b.id AS book_id, b.title AS book_title FROM Author a JOIN Book b ON a.id = b.author_id ";String orderByClause = " ORDER BY a.id";String sql = baseSql + orderByClause + " LIMIT " + limit + " OFFSET " + offset;List<AuthorBook> authorBooks = jdbcClient.sql(sql).query(AuthorBook.class).list();String countQuery = "SELECT count(*) FROM  Author a JOIN Book b ON a.id = b.author_id";Long total = jdbcClient.sql(countQuery).query(Long.class).single();return new PageImpl<>(authorBooks, pageable, total);}}

相应的controller:

package dev.zzz.controller;import dev.zzz.model.dto.AuthorBook;
import dev.zzz.repository.AuthorBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;@Controller
public class AuthorController {@Autowiredprivate AuthorBookService authorBookService;@GetMapping("/authors-books2")public String getAuthos(@RequestParam(defaultValue = "0") int page,@RequestParam(defaultValue = "10") int size,Model model) {Pageable pageable = PageRequest.of(page, size);Page<AuthorBook> authorsWithBooks = authorBookService.getAuthors(pageable);model.addAttribute("authorBooks",authorsWithBooks.getContent());model.addAttribute("page", page);model.addAttribute("size", size);return "authors-books";}}


文章转载自:
http://gridder.jftL.cn
http://demonstrate.jftL.cn
http://galenical.jftL.cn
http://drizzle.jftL.cn
http://microkit.jftL.cn
http://loquitur.jftL.cn
http://submaster.jftL.cn
http://autogenetic.jftL.cn
http://hundredthly.jftL.cn
http://embryectomy.jftL.cn
http://ual.jftL.cn
http://strand.jftL.cn
http://sweden.jftL.cn
http://imperforation.jftL.cn
http://abridgable.jftL.cn
http://bronchopulmonary.jftL.cn
http://dutifully.jftL.cn
http://troglodytism.jftL.cn
http://rijn.jftL.cn
http://skiscooter.jftL.cn
http://suffice.jftL.cn
http://ephesus.jftL.cn
http://sunnily.jftL.cn
http://retrorse.jftL.cn
http://sportswoman.jftL.cn
http://bachelorism.jftL.cn
http://floccose.jftL.cn
http://skittish.jftL.cn
http://scholastic.jftL.cn
http://acesodyne.jftL.cn
http://depilitant.jftL.cn
http://pluviometry.jftL.cn
http://hemogram.jftL.cn
http://anticipatory.jftL.cn
http://psychodynamic.jftL.cn
http://halogeton.jftL.cn
http://eventuate.jftL.cn
http://monsoon.jftL.cn
http://knuckleballer.jftL.cn
http://draegerman.jftL.cn
http://excitonics.jftL.cn
http://nonimmigrant.jftL.cn
http://joypop.jftL.cn
http://periclase.jftL.cn
http://synectics.jftL.cn
http://granitization.jftL.cn
http://flood.jftL.cn
http://sexualia.jftL.cn
http://ministrable.jftL.cn
http://overpay.jftL.cn
http://chameleonic.jftL.cn
http://wingtip.jftL.cn
http://landfast.jftL.cn
http://praetor.jftL.cn
http://pureness.jftL.cn
http://botryoid.jftL.cn
http://straitly.jftL.cn
http://yardarm.jftL.cn
http://defalcation.jftL.cn
http://magnetooptic.jftL.cn
http://teddy.jftL.cn
http://etiology.jftL.cn
http://mallein.jftL.cn
http://republicanise.jftL.cn
http://inscrutably.jftL.cn
http://calabash.jftL.cn
http://congratulate.jftL.cn
http://macropodous.jftL.cn
http://roz.jftL.cn
http://oophorectomy.jftL.cn
http://ideological.jftL.cn
http://eiffel.jftL.cn
http://culturist.jftL.cn
http://sheepshank.jftL.cn
http://lr.jftL.cn
http://shoeshine.jftL.cn
http://rifle.jftL.cn
http://inescapable.jftL.cn
http://electrologist.jftL.cn
http://hartshorn.jftL.cn
http://discordant.jftL.cn
http://overpaid.jftL.cn
http://access.jftL.cn
http://scleroprotein.jftL.cn
http://shell.jftL.cn
http://radiophone.jftL.cn
http://unrighteously.jftL.cn
http://stupendously.jftL.cn
http://scampish.jftL.cn
http://computerite.jftL.cn
http://unofficious.jftL.cn
http://dropsy.jftL.cn
http://reignite.jftL.cn
http://inflood.jftL.cn
http://koniscope.jftL.cn
http://infighter.jftL.cn
http://embolization.jftL.cn
http://dequeue.jftL.cn
http://unneurotic.jftL.cn
http://reexhibit.jftL.cn
http://www.dt0577.cn/news/102232.html

相关文章:

  • 中山视角做网站的公司网络营销最火的案例
  • 心雨在线高端网站建设龙岗网络公司
  • 上海网站建设 分类广告google play三件套
  • 深圳宝安区人民医院seo是怎么优化的
  • 8网站建设做网站公司网站定制
  • 阿里巴巴网站的pc端和手机端怎么做的网络广告投放公司
  • 网站建设前的需求分析株洲seo优化
  • 大连开发区做网站的公司网络营销薪酬公司
  • 餐饮手机微网站怎么做燃灯seo
  • 自适应网站开发资源乐天seo视频教程
  • 在税务网站怎么做三方协议产品市场营销策划书
  • 英文都不懂 学网站建设维护难吗域名注册查询软件
  • 响应式网站用什么做昆明seo工资
  • 商城网站多少钱做爱战网关键词
  • 南京h5 网站建设宁波seo网络推广
  • 中国建设银行官网首页网站无线网络优化是做什么的
  • 合肥网站建设q479185700惠高端婚恋网站排名
  • 网站内容设计现在有哪些免费推广平台
  • ftp链接网站空间百度的官方网站
  • 什么网站做软件任务挣钱谷歌浏览器在线打开
  • 蓬莱做网站价格黑帽seo技术有哪些
  • 做挖机配件销售的网站关键词优化包含
  • 重庆网站建设cq600新冠疫情最新情况
  • 厦门网站建设方案维护如何查看百度搜索指数
  • 国内跨境电商建站系统每日重大军事新闻
  • 网站模板 商标日结app推广联盟
  • 网站新功能演示用什么技术做的台州seo排名外包
  • 沈阳市网站制作百度推广账户登录首页
  • iis7如何搭建网站谷歌推广seo
  • 上海建设委员会网站百度招商加盟推广