日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

SpringBoot入门学习(五)之旅游网站项目

發(fā)布時(shí)間:2023/12/29 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot入门学习(五)之旅游网站项目 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

1、項(xiàng)目需求

2、技術(shù)需求

3、pom.xml

4、application.yml

4、MybatisPlus的配置文件

5、springboot中配置日期類型轉(zhuǎn)換器

6、用戶管理

7、線路管理

8、旅游公司管理

9、旅游線路管理

?10、部分功能……

?11、源碼下載


1、項(xiàng)目需求

用戶展示 旅游線路展示 線路圖片上傳與刪除 線路分類 展示 旅行社展示

?

2、技術(shù)需求

前臺(tái)有的老,學(xué)技術(shù)就可以了

后臺(tái)技術(shù) springbootmybatis-plus 前臺(tái) bootstrapjquerythymeleaffifileinput插件 數(shù)據(jù)庫(kù) mysql

3、pom.xml

<groupId>com.qinluyu</groupId><artifactId>SpringBoot04</artifactId><version>1.0-SNAPSHOT</version><!-- war/jar類型,可在其他服務(wù)器上運(yùn)行--><packaging>war</packaging><!-- jdk版本--><properties><java.version>1.8</java.version></properties><!--添加父工程坐標(biāo)--><parent><artifactId>spring-boot-starter-parent</artifactId><groupId>org.springframework.boot</groupId><version>2.3.0.RELEASE</version><relativePath/></parent><!--添加web啟動(dòng)器--><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- springboot整合數(shù)據(jù)庫(kù)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><!-- 測(cè)試test--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!-- mysql--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.45</version></dependency><!--配置文件啟動(dòng)器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency><!--mybatis-plus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version></dependency><!--分頁(yè)--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.1.10</version></dependency><!--thymeleaf--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!--lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency><!--文件上傳--><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.3</version></dependency><!--maven--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!--可不加版本號(hào)--><version>2.5.6</version></dependency></dependencies>

4、application.yml

server:port: 9091servlet:context-path: / spring:datasource:url: jdbc:mysql://127.0.0.1:3306/travel?characterEncoding=utf8?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMTusername: rootpassword: 123driver-class-name: com.mysql.jdbc.Driverhikari:idle-timeout: 60000maximum-pool-size: 30minimum-idle: 10 thymeleaf:cache: false mybatis-plus:mapper-locations: classpath:/mybatis/*.xml#加載映射文件type-aliases-package: com.qinluyu.domain#別名搜索的包c(diǎn)onfiguration:lazy-loading-enabled: true#打開懶加載aggressive-lazy-loading: false #關(guān)閉積極懶加載

4、MybatisPlus的配置文件

/*** MybatisPlus的配置文件*/ @Configuration @MapperScan("com.qinluyu.dao") public class MybatisPlusConfig {@Beanpublic PageInterceptor pageInterceptor(){return new PageInterceptor();} }

5、springboot中配置日期類型轉(zhuǎn)換器

/*** springboot中配置日期類型轉(zhuǎn)換器*/ @Component public class DateConverterConfig implements Converter<String, Date> {private static final List<String> formarts = new ArrayList<>(4);static{formarts.add("yyyy-MM");formarts.add("yyyy-MM-dd");formarts.add("yyyy-MM-dd hh:mm");formarts.add("yyyy-MM-dd hh:mm:ss");}@Override public Date convert(String source) {String value = source.trim();if ("".equals(value)) {return null;}if(source.matches("^\\d{4}-\\d{1,2}$")){return parseDate(source, formarts.get(0));}else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")){return parseDate(source, formarts.get(1));}else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")){return parseDate(source, formarts.get(2));}else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")){return parseDate(source, formarts.get(3));}else {throw new IllegalArgumentException("Invalid boolean value '" + source + "'");}}/**** 格式化日期* @param dateStr String 字符型日期* @param format String 格式* @return Date 日期*/public Date parseDate(String dateStr, String format) {Date date=null;try {DateFormat dateFormat = new SimpleDateFormat(format);date = dateFormat.parse(dateStr);}catch (Exception e) {}return date;} }

6、用戶管理

(1)實(shí)體類

@Data @TableName("tab_user") public class User implements Serializable{/*** 自增*/@TableId(type = IdType.AUTO)private Integer uid;private String username;private String password;private String name;private Date birthday;private String sex;private String telephone;private String email;private String status;private String code;private Boolean isadmin; }

(2)Dao類

public interface UserDao extends BaseMapper<User> { }

(3)Service類

public interface UserService {/*** 分頁(yè)* @param condition* @param pageNum* @param pageSize* @return user,pageNum,pageSize*/public PageInfo<User> findPage(User condition, int pageNum, int pageSize);/*** 查詢* @param condition* @return user*/public List<User> find(User condition);/*** 添加* @param user* @return*/public int add(User user);/*** 根據(jù)id用戶* @param id* @return*/public User findById(Integer id);/*** 更新* @param user* @return*/public int update(User user);/*** 刪除* @param id* @return*/public int delete(Integer id); }

(4)Service的實(shí)現(xiàn)類(重寫)

@Service public class UserServiceImpl implements UserService {/*** 需要寫引用*//*@Autowiredprivate UserDao userDao;*/@Resourceprivate UserDao userDao;/*** 分頁(yè)* @param condition* @param pageNum* @param pageSize* @return*/@Overridepublic PageInfo<User> findPage(User condition, int pageNum, int pageSize) {return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->{userDao.selectList(Wrappers.<User>query());});}/*** 查詢* @param condition* @return*/@Overridepublic List<User> find(User condition) {return userDao.selectList(Wrappers.query());}/*** 增加* @param user* @return*/@Overridepublic int add(User user) {return userDao.insert(user);}/*** 根據(jù)id查詢* @param id* @return*/@Overridepublic User findById(Integer id) {return userDao.selectById(id);}/*** 更新* @param user* @return*/@Overridepublic int update(User user) {return userDao.updateById(user);}/*** 刪除* @param id* @return*/@Overridepublic int delete(Integer id) {return userDao.deleteById(id);} }

(5)controller類

@Controller @RequestMapping("/admin/user") public class UserController {@Resourceprivate UserService userService;/***分頁(yè)查詢* @param user* @param pageNum* @param pageSize* @param model* @return*/@RequestMapping("/page")public String page(User user, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10")Integer pageSize, Model model){PageInfo<User> page = userService.findPage(user, pageNum, pageSize);model.addAttribute("page", page);return "/user/list";}/*** 跳到添加頁(yè)面* @return*/@RequestMapping("/toadd")public String toAdd() {return "/user/add";}/*** 添加* @param user* @return*/@RequestMapping("/doadd")public String doAdd(User user) {userService.add(user);return "redirect:/admin/user/page";}/*** 跳到修改頁(yè)面* @param id* @param model* @return*/@RequestMapping("/toupdate/{id}")public String toUpdate(@PathVariable("id") Integer id, Model model) {User user = userService.findById(id);model.addAttribute("user", user);return "/user/update";}/*** 更新* @param user* @return*/@RequestMapping("/doupdate")public String doUpdate(User user) {userService.update(user);return "redirect:/admin/user/page";}/*** 刪除* @param id* @return*/@RequestMapping("/delete/{id}")public String delete(@PathVariable("id") Integer id) {userService.delete(id);return "redirect:/admin/user/page";}/*** 批量刪除* @param ids* @return*/@RequestMapping("/delete")public String batchDelete(@RequestParam("ids") Integer[] ids) {for (Integer id : ids) {userService.delete(id);}return "redirect:/admin/user/page";}

(6)前端分頁(yè)

<div><nav aria-label="Page navigation"><ul class="pagination"><li id="first"><a href="javascript:void(0);"><span aria-hidden="true">首頁(yè)</span></a></li><li id="prev"><a href="javascript:void(0);" aria-label="Previous"><span aria-hidden="true">上一頁(yè)</span></a></li><li name="pageNum" th:each="i : ${page.navigatepageNums}" th:class="${i == page.pageNum} ? 'active'"><a href="javascript:void(0);" th:text="${i}"></a> </li><li id="next"><a href="javascript:void(0);" aria-label="Next"><span aria-hidden="true">下一頁(yè)</span></a></li><li id="last"><a href="javascript:void(0);"><span aria-hidden="true">末頁(yè)</span></a></li><span style="font-size: 20px;margin-left: 5px;"th:text="|共條 記錄,共${page.pages}頁(yè),每頁(yè)${page.pageSize}行數(shù)|"></span><select id="setRows"><option value="5" th:selected="${5 == page.pageSize}">5</option><option value="10" th:selected="${10 == page.pageSize}">10</option><option value="20" th:selected="${20 == page.pageSize}">20</option><option value="30" th:selected="${30 == page.pageSize}">30</option></select></ul></nav></div><script th:inline="javascript">$(function(){//初始化變量var pageNum = [[${page.pageNum}]];//當(dāng)前頁(yè)var pageCount = [[${page.pages}]];//最后頁(yè)var hasNextPage = [[${page.hasNextPage}]];//還有下一頁(yè)var hasPreviousPage = [[${page.hasPreviousPage}]];//還有上一頁(yè)if (!hasPreviousPage) {$("#prev").addClass("disabled");$("#first").addClass("disabled");}if (!hasNextPage) {$("#next").addClass("disabled");$("#last").addClass("disabled");}$("#first").click(function() {if (!$("#first").hasClass("disabled")) {$("#pageNum").val(1); $("#qf").submit();}});$("#prev").click(function() {if (!$("#prev").hasClass("disabled")) {$("#pageNum").val(pageNum - 1); $("#qf").submit();}});$("#next").click(function() {if (!$("#next").hasClass("disabled")) {$("#pageNum").val(pageNum + 1);$("#qf").submit(); } }); $("#last").click(function() {if (!$("#last").hasClass("disabled")) {$("#pageNum").val(pages); $("#qf").submit();}});$("li[name='pageNum']").click(function(){if (!$(this).hasClass("active")) {$("#pageNum").val($(this).children("a").html());$("#qf").submit();}});//設(shè)置每頁(yè)行數(shù)$("#setRows").change(function(){$("#pageSize").val($(this).val());$("#pageNum").val(1);$("#qf").submit();});});</script>

(7)添加(刪除)數(shù)據(jù)后回顯

<div class="page-content"><form action="/admin/user/doupdate" method="post" th:object="${user}"><input type="hidden" name="uid" th:value="${user.uid}"><div class="form-group"><label for="name">姓名:</label><input type="text" class="form-control" id="name" name="name" placeholder="請(qǐng)輸入姓名" th:value="*{name}"></div><div class="form-group"><label>性別:</label><input type="radio" name="sex" value="男" th:checked="'男' == *{sex}" />男<input type="radio" name="sex" value="女" th:checked="'女' == *{sex}" />女</div><div class="form-group"><label for="birthday">生日:</label><input type="text" class="form-control" id="birthday" name="birthday" placeholder="請(qǐng)輸入生日" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd'})" th:value="*{birthday}"></div><div class="form-group"><label for="telephone">電話:</label><input type="text" class="form-control" name="telephone" id="telephone" placeholder="請(qǐng)輸入電話" th:value="*{telephone}"/></div><div class="form-group"><label for="email">Email:</label><input type="text" class="form-control" name="email" id="email" placeholder="請(qǐng)輸入郵箱地址" th:value="*{email}"/></div><div class="form-group"><label for="username">登錄名</label><input type="text" class="form-control" name="username" id="username" placeholder="請(qǐng)輸入登錄名" th:value="*{username}"/></div><div class="form-group"><label for="password">密碼</label><input type="text" class="form-control" name="password" id="password" placeholder="請(qǐng)輸入密碼" th:value="*{password}"/></div><div class="form-group" style="text-align: center"><input class="btn btn-primary" type="submit" value="提交" /><input class="btn btn-default" type="reset" value="重置" /><input class="btn btn-default" type="button" value="返回" /></div></form></div>

7、線路管理

8、旅游公司管理

9、旅游線路管理

(1)圖片上傳

private void performRImage(Route route, @RequestParam("rimageFile") MultipartFile rimageFile, HttpServletRequest request) throws IOException {String savePath = request.getServletContext().getRealPath("img/product/rimage/");String fileName = UUID.randomUUID().toString().replaceAll("-", "") + "." + FilenameUtils.getExtension(rimageFile.getOriginalFilename());File savePathDir = new File(savePath);if (!savePathDir.exists()) {savePathDir.mkdirs();}rimageFile.transferTo(new File(savePathDir, fileName));route.setRimage("img/product/rimage/" + fileName);}/*** 根據(jù)id加載線路圖片,跳到image.html* @param id* @param model* @return*/@RequestMapping("/toimage")public String toImage(Integer id, Model model) {Route route = routeService.findById(id);model.addAttribute("route", route);return "route/image";}@RequestMapping("/doimage")public String doImage(Integer rid,@RequestParam("bigPicFile") MultipartFile[] bigPicFile,@RequestParam("smallPicFile")MultipartFile[] smallPicFile,HttpServletRequest request) throws Exception {List<String> bigPic = new ArrayList<>();List<String> smallPic = new ArrayList<>();String path = request.getServletContext().getRealPath("/");for (MultipartFile f : bigPicFile) {File bigPath = new File(path + "img\\product\\big-pic\\");if (!bigPath.exists()) {bigPath.mkdirs();}String fileName = UUID.randomUUID().toString().replace("-", "") + "." +FilenameUtils.getExtension(f.getOriginalFilename());f.transferTo(new File(bigPath, fileName));bigPic.add("img/product/big-pic/" + fileName);}for (MultipartFile f : smallPicFile) {File smallPath = new File(path + "img\\product\\small-pic\\");if (!smallPath.exists()) {smallPath.mkdirs();}String fileName = UUID.randomUUID().toString().replace("-", "") + "." +FilenameUtils.getExtension(f.getOriginalFilename());f.transferTo(new File(smallPath, fileName));smallPic.add("img/product/small-pic/" + fileName);} //要添加的圖片列表List<RouteImg> ris = new ArrayList<>();for (int i=0; i<bigPic.size(); i++) {RouteImg img = new RouteImg();img.setRid(rid);img.setBigpic(bigPic.get(i));img.setSmallpic(smallPic.get(i));ris.add(img);}imgService.saveImg(rid, ris);return "redirect:/admin/route/page";}

?10、部分功能……

經(jīng)測(cè)試后,基本功能實(shí)現(xiàn)

部分功能還需再寫,比如分類管理可以添加、刪除卻不能修改

圖片如果是空,則提交不了

等等

?11、源碼下載

SpringBoot入門學(xué)習(xí)之旅游網(wǎng)站項(xiàng)目-Java文檔類資源-CSDN下載

總結(jié)

以上是生活随笔為你收集整理的SpringBoot入门学习(五)之旅游网站项目的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。