Spring Into HTML and CSS

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp
The fastest route to true HTML/CSS mastery!Need to build a web site? Or update one? Or just create some effective new web content? Maybe you just need to update your skills, do the job better.Welcome. This book's for you. We'll leverage what you already know about the web, so you'll go further, faster than you ever expected. You'll master today's best practices: the real nuts and bolts, not theory or hooey. You'll learn through dozens of focused HTML, XHTML, and CSS examples: crafted for simplicity and easy to adapt for your own projects.Need specific solutions? This book's modular, visual, high-efficiency format delivers them instantly. Molly E. Holzschlag draws on her unparalleled experience teaching Web design and development. No other HTML/CSS guide covers this much, this well, this quickly. Dig in, get started, get results! All you need to succeed with HTML, XHTML, and CSS in real-world projects Learn how to build web pages that'll work in any environment, on virtually any contemporary browser Construct templates that simplify every page you develop Structure and tag text so it's easy to work with and manage Add images, media, and scriptsquickly and reliably Discover the right ways to use HTML tables Build easy-to-use forms and validate your users' input Use CSS to take total control over your site's look and feel Master core CSS techniques: color, images, text styles, link effects, lists, navigation, and more Control margins, borders, padding, positioning, floats, even Z-index Design efficient, compatible, easy-to-manage CSS layoutsIncludes concise XHTML and CSS annotated references: quick help for every language elementSpring Into... is a new series of fast-paced tutorials from Addison-Wesley. Each book in the series is designed to bring you up to speed quickly. Complex topics and technologies are reduced to their core components, and each component is treated with remarkable efficiency in one- or two-page spreads. Just the information you need to begin working...now! And because the books are example-rich and easy to navigate, you'll find that they make great on-the-job references after you've mastered the basics.
http://rapidshare.com/files/52578825/0131855867.zip
很抱歉,我无法在这里提供完整的代码和配置,因为这需要较多的篇幅和时间来完成。但是,我可以提供一些参考和指导来帮助你完成这个项目。 首先,你需要创建一个MySQL数据库,包含一个名为"book"的表,该表包含id、name、author、price和description等字段。可以使用以下SQL语句来创建该表: ``` CREATE TABLE book ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(50) DEFAULT NULL, author varchar(50) DEFAULT NULL, price double(10,2) DEFAULT NULL, description varchar(200) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ``` 然后,你需要在Spring中配置Mybatis,以便从Java代码中访问该数据库。可以在applicationContext.xml文件中添加以下配置: ``` <!-- 配置Mybatis --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.example.mapper"/> </bean> <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/book?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai"/> <property name="username" value="root"/> <property name="password" value="123456"/> </bean> ``` 其中,mybatis-config.xml文件包含了Mybatis的其他配置,可以在该文件中添加以下内容: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="cacheEnabled" value="true"/> <setting name="lazyLoadingEnabled" value="true"/> </settings> <typeAliases> <package name="com.example.entity"/> </typeAliases> <mappers> <mapper class="com.example.mapper.BookMapper"/> </mappers> </configuration> ``` 在该项目中,你需要创建一个Book实体类来表示图书信息,可以使用以下代码: ``` public class Book { private Integer id; private String name; private String author; private Double price; private String description; // 省略getter和setter方法 } ``` 为了将该实体类映射到数据库中,你需要创建一个BookMapper接口和一个BookMapper.xml文件。可以使用以下代码: ``` public interface BookMapper { List<Book> findAll(); void insert(Book book); void update(Book book); void delete(Integer id); Book findById(Integer id); } ``` ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.mapper.BookMapper"> <resultMap type="com.example.entity.Book" id="book"> <id column="id" property="id"/> <result column="name" property="name"/> <result column="author" property="author"/> <result column="price" property="price"/> <result column="description" property="description"/> </resultMap> <select id="findAll" resultMap="book"> select * from book </select> <insert id="insert"> insert into book(name, author, price, description) values(#{name}, #{author}, #{price}, #{description}) </insert> <update id="update"> update book set name=#{name}, author=#{author}, price=#{price}, description=#{description} where id=#{id} </update> <delete id="delete"> delete from book where id=#{id} </delete> <select id="findById" resultMap="book"> select * from book where id=#{id} </select> </mapper> ``` 最后,你需要创建一个BookController类来处理Web请求,并使用Thymeleaf模板引擎来渲染页面。可以使用以下代码: ``` @Controller public class BookController { @Autowired private BookMapper bookMapper; @GetMapping("/") public String index(Model model) { List<Book> books = bookMapper.findAll(); model.addAttribute("books", books); return "index"; } @GetMapping("/add") public String add() { return "add"; } @PostMapping("/save") public String save(Book book) { bookMapper.insert(book); return "redirect:/"; } @GetMapping("/edit/{id}") public String edit(@PathVariable Integer id, Model model) { Book book = bookMapper.findById(id); model.addAttribute("book", book); return "edit"; } @PostMapping("/update") public String update(Book book) { bookMapper.update(book); return "redirect:/"; } @GetMapping("/delete/{id}") public String delete(@PathVariable Integer id) { bookMapper.delete(id); return "redirect:/"; } } ``` 在resources/templates目录下,你需要创建以下Thymeleaf模板文件: index.html: ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>图书管理系统</title> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css"> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <h2>图书列表</h2> <hr> <div class="text-right"> <a href="/add" class="btn btn-primary">添加图书</a> </div> <table class="table table-bordered table-striped"> <thead> <tr> <th>编号</th> <th>书名</th> <th>作者</th> <th>价格</th> <th>描述</th> <th>操作</th> </tr> </thead> <tbody> <tr th:each="book : ${books}"> <td th:text="${book.id}"></td> <td th:text="${book.name}"></td> <td th:text="${book.author}"></td> <td th:text="${book.price}"></td> <td th:text="${book.description}"></td> <td> <a th:href="@{/edit/{id}(id=${book.id})}" class="btn btn-info btn-sm">编辑</a> <a th:href="@{/delete/{id}(id=${book.id})}" class="btn btn-danger btn-sm" onclick="return confirm('确定要删除吗?')">删除</a> </td> </tr> </tbody> </table> </div> </div> </div> </body> </html> ``` add.html: ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>添加图书</title> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css"> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <h2>添加图书</h2> <hr> <form th:action="@{/save}" method="post"> <div class="form-group"> <label>书名:</label> <input type="text" name="name" class="form-control" required> </div> <div class="form-group"> <label>作者:</label> <input type="text" name="author" class="form-control" required> </div> <div class="form-group"> <label>价格:</label> <input type="number" name="price" class="form-control" step="0.01" required> </div> <div class="form-group"> <label>描述:</label> <textarea name="description" class="form-control" rows="3" required></textarea> </div> <div class="text-right"> <button type="submit" class="btn btn-primary">保存</button> <a href="/" class="btn btn-secondary">取消</a> </div> </form> </div> </div> </div> </body> </html> ``` edit.html: ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>编辑图书</title> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css"> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <h2>编辑图书</h2> <hr> <form th:action="@{/update}" method="post"> <input type="hidden" name="id" th:value="${book.id}"> <div class="form-group"> <label>书名:</label> <input type="text" name="name" class="form-control" th:value="${book.name}" required> </div> <div class="form-group"> <label>作者:</label> <input type="text" name="author" class="form-control" th:value="${book.author}" required> </div> <div class="form-group"> <label>价格:</label> <input type="number" name="price" class="form-control" step="0.01" th:value="${book.price}" required> </div> <div class="form-group"> <label>描述:</label> <textarea name="description" class="form-control" rows="3" th:text="${book.description}" required></textarea> </div> <div class="text-right"> <button type="submit" class="btn btn-primary">保存</button> <a href="/" class="btn btn-secondary">取消</a> </div> </form> </div> </div> </div> </body> </html> ``` 最后,你需要在pom.xml文件中添加以下依赖: ``` <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.29</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> </dependencies> ``` 以上就是一个简单的图书管理系统的实现,希望能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值