spring boot 简单mvc demo,Spring boot示例

Spring boot示例。只做了一个查询功能,项目目录结构,使用eclipse建立的spring starter project项目。没做其他改动。

spring boot 简单mvc demo,Spring boot示例_第1张图片


pom.xml


		org.springframework.boot
		spring-boot-starter-parent
		2.0.2.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
			org.projectlombok
			lombok
			1.16.20
		
		
			org.springframework.boot
			spring-boot-starter-web
		
		
			mysql
			mysql-connector-java
			runtime
		
		
			org.springframework.boot
			spring-boot-starter-data-jpa
		
		
			org.springframework.boot
			spring-boot-starter-thymeleaf
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	

实体类,getter与setter使用的是lombok,有了lombok省的总写一堆浪费时间的getter setter toString 等等。

使用方法见https://blog.csdn.net/tangyaliang11/article/details/80275959

@Data
@Entity(name = "chinese_drug_specification")
public class ChineseDrugSpecification {
	/**
	 * 主键
	 */
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	/**
	 * 通用名
	 */
	@Column(name = "common_name")
	private String commonName;
	/**
	 * 别名
	 */
	@Column(name = "alias")
	private String alias;
	/**
	 * 全拼
	 */
	@Column(name = "fullcn_name")
	private String fullcnName;
	/**
	 * 英文名
	 */
	@Column(name = "eng_name")
	private String engName;
	/**
	 * 来源
	 */
	@Column(name = "source")
	private String source;
	/**
	 * 性状
	 */
	@Column(name = "characters")
	private String characters;
	/**
	 * 炮制
	 */
	@Column(name = "processing")
	private String processing;
	/**
	 * 性味
	 */
	@Column(name = "sexual")
	private String sexual;
	/**
	 * 归经
	 */
	@Column(name = "flavour")
	private String flavour;
	/**
	 * 鉴别
	 */
	@Column(name = "identify")
	private String identify;
	/**
	 * 检查
	 */
	@Column(name = "inspection")
	private String inspection;
	/**
	 * 浸出物
	 */
	@Column(name = "extract")
	private String extract;
	/**
	 * 含量测定
	 */
	@Column(name = "content_determination")
	private String contentDetermination;
	/**
	 * 功效
	 */
	@Column(name = "fun")
	private String fun;
	/**
	 * 用法用量
	 */
	@Column(name = "usages")
	private String usages;
	/**
	 * 注意事项
	 */
	@Column(name = "attention")
	private String attention;
	/**
	 * 贮藏
	 */
	@Column(name = "storage")
	private String storage;
	/**
	 * 文献来源
	 */
	@Column(name = "literature")
	private String literature;
	/**
	 * 
	 */
	@Column(name = "medicinal")
	private Integer medicinal;
	/**
	 * 
	 */
	@Column(name = "taste")
	private String taste;
	/**
	 * 
	 */
	@Column(name = "tropism")
	private String tropism;
	/**
	 * 
	 */
	@Column(name = "effect")
	private String effect;
}

仓库

public interface ChineseDrugRepository extends Repository {
	ChineseDrugSpecification findById(Integer id);
}

控制层

@Controller
@RequestMapping("/")
public class ChineseDrugController {
	@Autowired
	private ChineseDrugRepository readingListRepository;

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public String readersBooks(@PathVariable("id") Integer id, Model model) {
		ChineseDrugSpecification chineseDrug = readingListRepository.findById(id);
		if (chineseDrug != null) {
			model.addAttribute("chineseDrug", chineseDrug);
		}
		return "readingList";
	}
}

页面。名称叫做readingList.html,页面技术采用的是thymeleaf



      
      	
      	
      	
      	
        Reading List
        
      

	

Your Reading List

Title

css 

body {
	background-color: #cccccc;
	font-family: arial, helvetica, sans-serif;
}

.bookHeadline {
	font-size: 12pt;
	font-weight: bold;
}

.bookDescription {
	font-size: 10pt;
}

label {
	font-weight: bold;
}

application.yml配置

spring:
  datasource: 
      username: root
      password: 123
      url: jdbc:mysql://192.168.1.6:3306/engine
      driver-class-name: com.mysql.jdbc.Driver

sql语句 ,注意您的mysql数据库字符集避免乱码。

CREATE USER engine;
create table chinese_drug_specification
(
	id int not null primary key,
	common_name varchar(200) null,
	alias varchar(200) null,
	fullcn_name varchar(100) null,
	eng_name varchar(100) null,
	source varchar(2000) null,
	characters varchar(2000) null,
	processing varchar(2000) null,
	sexual varchar(100) null,
	flavour varchar(100) null,
	medicinal int null,
	taste varchar(100) null,
	tropism varchar(100) null,
	effect int null,
	fun varchar(400) null,
	usages varchar(200) null,
	attention varchar(200) null,
	literature varchar(50) null,
	identify varchar(2000) null,
	inspection varchar(2000) null,
	extract varchar(2000) null,
	storage varchar(500) null,
	content_determination text null
)
;
INSERT INTO engine.chinese_drug_specification (id, common_name, alias, fullcn_name, eng_name, source, characters, processing, sexual, flavour, medicinal, taste, tropism, effect, fun, usages, attention, literature, identify, inspection, extract, storage, content_determination) VALUES (1, '阿胶', '盆覆胶、驴皮胶、', 'Ejiao', 'ASINI CORII COLLA', '本品为马科动物驴Equus asinus L.的干燥皮或鲜皮经煎煮、浓缩制成的固体胶。', '本品呈长方形块、方形块或丁状。棕色至黑褐色,有光泽。质硬而脆,断面光亮,碎片对光照视呈棕色半透明状。气微,味微甘。', '阿胶  捣成碎块。
阿胶珠 取阿胶,烘软,切成lcm左右的丁,照烫法(附录ⅡD)用始粉烫至成珠,内无溏心时,取出,筛去蛤粉,放凉。
本品呈类球形。表面棕黄色或灰白色,附有白色粉末。体轻,质酥,易碎。断面中空或多孔状,淡黄色至棕色。气微,味微甜。', '甘、平。', '归肺、肝、肾经。', 322, '336、', '327、328、330、', 377, '补血滋阴,润燥,止血。用于血虚萎黄,眩晕心悸,肌痿无力,心烦不眠,虚风内动,肺燥咳嗽,劳嗽咯血,吐血尿血,便血崩漏,妊娠胎漏。', '3~9g。烊化兑服。', null, '中国药典2010版', null, null, null, null, null);

项目启动类

@SpringBootApplication
public class DrugApplication {
	public static void main(String[] args) {
		SpringApplication.run(DrugApplication.class, args);
	}
}

在浏览器地址栏输入:http://127.0.0.1:8080/1

spring boot 简单mvc demo,Spring boot示例_第2张图片

你可能感兴趣的:(spring,boot)